我使用策略保存程序保存了训练有素的策略,如下所示:
tf_policy_saver = policy_saver.PolicySaver(agent.policy)
tf_policy_saver.save(policy_dir)
Run Code Online (Sandbox Code Playgroud)
我想继续使用保存的策略进行训练。所以我尝试使用保存的策略初始化训练,这导致了一些错误。
agent = dqn_agent.DqnAgent(
tf_env.time_step_spec(),
tf_env.action_spec(),
q_network=q_net,
optimizer=optimizer,
td_errors_loss_fn=common.element_wise_squared_loss,
train_step_counter=train_step_counter)
agent.initialize()
agent.policy=tf.compat.v2.saved_model.load(policy_dir)
Run Code Online (Sandbox Code Playgroud)
错误:
File "C:/Users/Rohit/PycharmProjects/pythonProject/waypoint.py", line 172, in <module>
agent.policy=tf.compat.v2.saved_model.load('waypoints\\Two_rewards')
File "C:\Users\Rohit\anaconda3\envs\btp36\lib\site-packages\tensorflow\python\training\tracking\tracking.py", line 92, in __setattr__
super(AutoTrackable, self).__setattr__(name, value)
AttributeError: can't set attribute
Run Code Online (Sandbox Code Playgroud)
我只是想节省每次重新训练的时间。如何加载保存的策略并继续训练?
提前致谢