问题描述
当我运行一些代码(DDPG - Deep Deterministic Policy Gradient)时,发生了这个错误:ValueError: callbacks
must be a callable method that return a subclass of DefaultCallbacks, got <class 'ray.rllib.agents.callbacks.DefaultCallbacks'>
when I run some codes(DDPG - Deep Deterministic Policy Gradient), this error occurred: ValueError: callbacks
must be a callable method that returns a subclass of DefaultCallbacks, got <class 'ray.rllib.agents.callbacks.DefaultCallbacks'>
我的代码在这里:
import json
def load_policy():
log_dir = "/root/ray_results/DDPG_SimpleSupplyChain_2020-07-15_02-37-48j2fjk67_" # this path needs to be set manually
checkpoint_id = "200"
with open(f"{log_dir}/params.json", "r") as read_file:
config = json.load(read_file)
trainer = ddpg.DDPGTrainer(config=config, env=SimpleSupplyChain)
trainer.restore(f"{log_dir}/checkpoint_{checkpoint_id}/checkpoint-{checkpoint_id}")
return trainer.get_policy()
policy = load_policy()
log_dir 是经过训练的 DDPG 参数的位置.
log_dir is location of trained DDPG's parameters.
我想使用经过训练的参数,所以使用config = json.load(read_file)";代码.
I want to use trained parameters, so use "config = json.load(read_file)" code.
然后,当我制作 DDPGTrainer 时,使用此配置",但发生了一些错误.
then, when I make DDPGTrainer, use this "config", but some errors occurred.
我该如何解决这个错误?
How can I solve this error?
推荐答案
我怀疑您的 params.json
具有回调类的字符串表示形式.config dict 应该为回调保存一个真正的 Python 对象,而不是字符串表示.您可以尝试加载配置的腌制版本,例如 RLlib 代码库中的 rollout.py
,而不是加载它的 JSON 表示.
I suspect your params.json
has a string representation of the callbacks class. The config dict should hold a real Python object for the callback, not a string representation. You could try loading the pickled version of the config, like in rollout.py
in the RLlib codebase, rather than loading the JSON representation of it.
这篇关于错误:`callbacks` 必须是返回 DefaultCallbacks 子类的可调用方法,得到 <class 'ray.rllib.agents.callbacks.DefaultCallbacks'>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!