简体   繁体   English

如何在 python 的大查询中存储 tf-agents 的轨迹对象并将其作为轨迹对象检索回来

[英]How to store tf-agents' trajectory object in big query from python and retrieve it back as the trajectory object

I wanted to save the trajectories from the tf-agents into a big query table and wanted to retrieve them back as needed into python again.我想将来自 tf-agents 的轨迹保存到一个大查询表中,并希望根据需要再次将它们检索到 python 中。

In the python dataframe, the trajectories are saved as trajectory object.在 python 数据框中,轨迹被保存为轨迹对象。 But, I am not sure how to save these trajectories object to big query and retrieve them back into python.但是,我不确定如何将这些轨迹对象保存到大查询中并将它们检索回 python。 Saving them as strings is not working nor is saving the individuals components (Action, reward etc. as strings) in big query.将它们保存为字符串不起作用,也不能在大查询中保存个人组件(动作、奖励等作为字符串)。

Here is a sample trajectory object that I Wanted to save and retrieve back as a trajectory into pandas这是一个示例轨迹对象,我想将其作为轨迹保存并检索回 pandas

Trajectory(
{'action': <tf.Tensor: shape=(1,), dtype=int32, numpy=array([2], dtype=int32)>,
 'discount': <tf.Tensor: shape=(1,), dtype=float32, numpy=array([0.], dtype=float32)>,
 'next_step_type': <tf.Tensor: shape=(1,), dtype=int32, numpy=array([2], dtype=int32)>,
 'observation': <tf.Tensor: shape=(1, 3), dtype=int32, numpy=array([[0, 1, 1]], dtype=int32)>,
 'policy_info': PolicyInfo(log_probability=(), predicted_rewards_mean=(), multiobjective_scalarized_predicted_rewards_mean=(), predicted_rewards_optimistic=(), predicted_rewards_sampled=(), bandit_policy_type=()),
 'reward': <tf.Tensor: shape=(1,), dtype=float32, numpy=array([-1000.], dtype=float32)>,
 'step_type': <tf.Tensor: shape=(1,), dtype=int32, numpy=array([2], dtype=int32)>})

Stored each trajectory as pickle data, using pickle.dumps(), to the big query column.使用 pickle.dumps() 将每个轨迹作为 pickle 数据存储到大查询列。 The big query data type used is 'bytes' for the trajectory object.使用的大查询数据类型是轨迹对象的“字节”。

Again retrieved the pickle back using pickle.dumps()再次使用 pickle.dumps() 取回泡菜

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM