[英]How to store tf-agents' trajectory object in big query from python and retrieve it back as the trajectory object
我想將來自 tf-agents 的軌跡保存到一個大查詢表中,並希望根據需要再次將它們檢索到 python 中。
在 python 數據框中,軌跡被保存為軌跡對象。 但是,我不確定如何將這些軌跡對象保存到大查詢中並將它們檢索回 python。 將它們保存為字符串不起作用,也不能在大查詢中保存個人組件(動作、獎勵等作為字符串)。
這是一個示例軌跡對象,我想將其作為軌跡保存並檢索回 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)>})
使用 pickle.dumps() 將每個軌跡作為 pickle 數據存儲到大查詢列。 使用的大查詢數據類型是軌跡對象的“字節”。
再次使用 pickle.dumps() 取回泡菜
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.