Unity-Technologies / ml-agents

The Unity Machine Learning Agents Toolkit (ML-Agents) is an open-source project that enables games and simulations to serve as environments for training intelligent agents using deep reinforcement learning and imitation learning.
https://unity.com/products/machine-learning-agents
Other
17.17k stars 4.16k forks source link

ModuleNotFoundError: No module named 'tensorflow.contrib' #3035

Closed albertoxamin closed 4 years ago

albertoxamin commented 4 years ago

Describe the bug I was following the example on creating a gym https://github.com/Unity-Technologies/ml-agents/blob/master/gym-unity/README.md#example---dqn-baseline so i installed the dependency pip install git+git://github.com/openai/baselines and then I created the train_unity.py script

import gym

from baselines import deepq
from baselines import logger

from gym_unity.envs.unity_env import UnityEnv

def main():
    env = UnityEnv("./envs/GridWorld", 0, use_visual=True, uint8_visual=True)
    logger.configure('./logs') # Çhange to log in a different directory
    act = deepq.learn(
        env,
        "cnn", # conv_only is also a good choice for GridWorld
        lr=2.5e-4,
        total_timesteps=1000000,
        buffer_size=50000,
        exploration_fraction=0.05,
        exploration_final_eps=0.1,
        print_freq=20,
        train_freq=5,
        learning_starts=20000,
        target_network_update_freq=50,
        gamma=0.99,
        prioritized_replay=False,
        checkpoint_freq=1000,
        checkpoint_path='./logs', # Change to save model in a different directory
        dueling=True
    )
    print("Saving model to unity_model.pkl")
    act.save("unity_model.pkl")

if __name__ == '__main__':
    main()

But when I proceed to execute it i get this error

python -m train_unity
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/Users/alberto/Documents/GitHub/HeterogenousCameraNetwork/mlagents-config/train_unity.py", line 3, in <module>
    from baselines import deepq
  File "/Users/alberto/python-envs/mlagents/lib/python3.6/site-packages/baselines/deepq/__init__.py", line 1, in <module>
    from baselines.deepq import models  # noqa
  File "/Users/alberto/python-envs/mlagents/lib/python3.6/site-packages/baselines/deepq/models.py", line 2, in <module>
    import tensorflow.contrib.layers as layers
ModuleNotFoundError: No module named 'tensorflow.contrib'

Environment:

chriselion commented 4 years ago

Hi @albertoxamin, This import is coming from OpenAI baselines, not ml-agents. It's likely that they're not compatible with the latest version of tensorflow.

olgn commented 4 years ago

you have the wrong version of tensorflow installed. as stated in the baselines installation instructions here tensorflow 1.14 is the latest tf version supported - and you have 2.0 installed

albertoxamin commented 4 years ago

Thanks @olgn, that solved that issue. However I encountered another one because the example was outdated. So I opened #3055 with the fixes.

olgn commented 4 years ago

@albertoxamin nice - I only could answer that question because I encountered it as well. Also ran into the module import error. glad to see you made an mr for that.

github-actions[bot] commented 3 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.