Error: `callbacks` must be a callable method that returns a subclass of DefaultCallbacks, got <class 'ray.rllib.agents.callbacks.DefaultCallbacks'>

亡梦爱人 提交于 2021-01-29 18:30:36

问题


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'>

my code is here:

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 is location of trained DDPG's parameters.

I want to use trained parameters, so use "config = json.load(read_file)" code.

then, when I make DDPGTrainer, use this "config", but some errors occurred.

How can I solve this error?


回答1:


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.



来源:https://stackoverflow.com/questions/62908522/error-callbacks-must-be-a-callable-method-that-returns-a-subclass-of-defaultc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!