araffin / rl-baselines-zoo

A collection of 100+ pre-trained RL agents using Stable Baselines, training and hyperparameter optimization included.
https://stable-baselines.readthedocs.io/
MIT License
1.12k stars 208 forks source link

ModuleNotFoundError: No module named 'stable_baselines.ddpg.memory', when loading ddpg pendulum-v0 #43

Closed ghost closed 4 years ago

ghost commented 4 years ago

Describe the bug ModuleNotFoundError: No module named 'stable_baselines.ddpg.memory', when loading ddpg pendulum-v0

Code example

from utils import ALGOS
folder = "trained_agents/zoo/"

def load_model(env_name, algo):
    algo_path = os.path.join(folder, algo)
    print(algo_path)
    assert os.path.isdir(algo_path), "The {} folder was not found".format(algo_path)

    found = False
    for ext in ['pkl', 'zip']:
        model_path = "{}/{}.{}".format(algo_path, env_name, ext)
        found = os.path.isfile(model_path)
        if found:
            break
    if not found:
        raise ValueError("No model found for {} on {}, path: {}".format(algo, env_name, model_path))

    nn_model = ALGOS[algo].load(model_path)

    return nn_model

if __name__ == "__main__":
    nn_model = load_model("Pendulum-v0", "ddpg")
Traceback (most recent call last):
  File "zoo_model.py", line 33, in <module>
    nn_model = load_model("Pendulum-v0", "ddpg")
  File "zoo_model.py", line 28, in load_model
    nn_model = ALGOS[algo].load(model_path)
  File "/home/zxiong/development/general_dev_p3/lib/python3.6/site-packages/stable_baselines/ddpg/ddpg.py", line 1104, in load
    data, params = cls._load_from_file(load_path, custom_objects=custom_objects)
  File "/home/zxiong/development/general_dev_p3/lib/python3.6/site-packages/stable_baselines/common/base_class.py", line 615, in _load_from_file
    data, params = BaseRLModel._load_from_file_cloudpickle(load_path)
  File "/home/zxiong/development/general_dev_p3/lib/python3.6/site-packages/stable_baselines/common/base_class.py", line 549, in _load_from_file_cloudpickle
    data, params = cloudpickle.load(file_)
ModuleNotFoundError: No module named 'stable_baselines.ddpg.memory'

System Info Describe the characteristic of your environment:

araffin commented 4 years ago

Hello,

Answer is both in the documentation and in the code: https://github.com/araffin/rl-baselines-zoo/blob/41902fdbe42574ad985189a4c9877047f43eb5d2/enjoy.py#L26-L29

"DDPG replay buffer was unified with DQN/SAC replay buffer. As a result, when loading a DDPG model trained with stable_baselines<2.6.0, it throws an import error. You can fix that using:"

Edit: please also provide stable-baselines version next time