Waterwheel
Waterwheel

Reputation: 31

ImportError: cannot import name 'network' from 'tensorflow.python.keras.engine'

Getting this error when trying to import tf_agents.environments running on Tensorflow 2.3.0, using anaconda environment. Have tried to reinstall tensorflow, still getting same error. Running the jupyter notebook in as admin, still getting same error. I am using python 3.8

from tf_agents.environments import suite_gym



ImportError                               Traceback (most recent call last)
<ipython-input-8-b9cd8ac2787f> in <module>
----> 1 from tf_agents.environments import suite_gym
      2 
      3 # env = suite_gym.load("Breakout-v4")
      4 # env

~\AppData\Roaming\Python\Python38\site-packages\tf_agents\environments\__init__.py in <module>
     24 from tf_agents.environments import tf_py_environment
     25 from tf_agents.environments import trajectory_replay
---> 26 from tf_agents.environments import utils
     27 from tf_agents.environments import wrappers

~\AppData\Roaming\Python\Python38\site-packages\tf_agents\environments\utils.py in <module>
     23 from tf_agents.environments import tf_environment
     24 from tf_agents.environments import tf_py_environment
---> 25 from tf_agents.policies import random_py_policy
     26 from tf_agents.specs import array_spec
     27 

~\AppData\Roaming\Python\Python38\site-packages\tf_agents\policies\__init__.py in <module>
     16 """Policies Module."""
     17 
---> 18 from tf_agents.policies import actor_policy
     19 from tf_agents.policies import boltzmann_policy
     20 from tf_agents.policies import epsilon_greedy_policy

~\AppData\Roaming\Python\Python38\site-packages\tf_agents\policies\actor_policy.py in <module>
     27 import tensorflow_probability as tfp
     28 
---> 29 from tf_agents.networks import network
     30 from tf_agents.policies import tf_policy
     31 from tf_agents.specs import tensor_spec

~\AppData\Roaming\Python\Python38\site-packages\tf_agents\networks\__init__.py in <module>
     16 """Networks Module."""
     17 
---> 18 from tf_agents.networks import actor_distribution_network
     19 from tf_agents.networks import actor_distribution_rnn_network
     20 from tf_agents.networks import bias_layer

~\AppData\Roaming\Python\Python38\site-packages\tf_agents\networks\actor_distribution_network.py in <module>
     24 import tensorflow as tf  # pylint: disable=g-explicit-tensorflow-version-import
     25 
---> 26 from tf_agents.networks import categorical_projection_network
     27 from tf_agents.networks import encoding_network
     28 from tf_agents.networks import network

~\AppData\Roaming\Python\Python38\site-packages\tf_agents\networks\categorical_projection_network.py in <module>
     24 import tensorflow_probability as tfp
     25 
---> 26 from tf_agents.networks import network
     27 from tf_agents.networks import utils
     28 from tf_agents.specs import distribution_spec

~\AppData\Roaming\Python\Python38\site-packages\tf_agents\networks\network.py in <module>
     31 
     32 # pylint:disable=g-direct-tensorflow-import
---> 33 from tensorflow.python.keras.engine import network as keras_network  # TF internal
     34 from tensorflow.python.training.tracking import base  # TF internal
     35 from tensorflow.python.util import tf_decorator  # TF internal

ImportError: cannot import name 'network' from 'tensorflow.python.keras.engine' (C:\Users\Vision\anaconda3\envs\tf2\lib\site-packages\tensorflow\python\keras\engine\__init__.py)

Upvotes: 3

Views: 8817

Answers (1)

Astrian_72954
Astrian_72954

Reputation: 411

Am a bit late here, but faced a similar issue.

How I resolved the issue :

Uninstall the current version of tf_agents, use

pip uninstall tf-agents

Please install the current tf-agents-nightly (0.6.0) GitHub Repo.

use pip install tf-agents-nightly

from tf_agents.environments import suite_gym

Upvotes: 4

Related Questions