tensorflow / tensor2tensor

Library of deep learning models and datasets designed to make deep learning more accessible and accelerate ML research.
Apache License 2.0
15.59k stars 3.51k forks source link

ModuleNotFoundError: No module named 'tensorflow.compat.v2' #1830

Open josiahcoad opened 4 years ago

josiahcoad commented 4 years ago

Description

I ran the following code in a Google Colab and get the error:

ModuleNotFoundError: No module named 'tensorflow.compat.v2'
!pip install -q tensorflow==1.13.1
!pip install -q tensorflow_probability==0.6.0
!pip install -q tensor2tensor==1.13.1
!pip install -q gym[atari]
!python -m tensor2tensor.rl.trainer_model_based \
  --loop_hparams_set=rlmb_base_stochastic_discrete \
  --loop_hparams=game=pong,epochs=1,ppo_epochs_num=0 \
  --output_dir=~/t2t_train/mb_sd_pong_random

$ pip freeze | grep tensor

mesh-tensorflow==0.1.16
tensor2tensor==1.13.1
tensorboard==1.13.1
tensorboard-plugin-wit==1.6.0.post3
tensorboardcolab==0.0.22
tensorflow==1.13.1
tensorflow-addons==0.8.3
tensorflow-datasets==2.1.0
tensorflow-estimator==1.13.0
tensorflow-gcs-config==2.2.0
tensorflow-hub==0.8.0
tensorflow-metadata==0.22.2
tensorflow-privacy==0.2.2
tensorflow-probability==0.6.0

$ python -V

Python 3.6.9
snowbabyjia commented 4 years ago

Same problem here

barton-wa commented 4 years ago

The versions of tensorflow and tensor2tensor are incompatible

barton-wa commented 4 years ago

I‘m using tensorflow1.15.0 tensor2tensor1.14.1

Hyperion-shuo commented 4 years ago

i installed tensor2tensor1.14.1 and tensorflow 1.15.0 on Colab

tensor2tensor            1.14.1         
tensorboard              1.15.0         
tensorboard-plugin-wit   1.7.0          
tensorboardcolab         0.0.22         
tensorflow               1.15.0         
tensorflow-addons        0.8.3          
tensorflow-datasets      2.1.0          
tensorflow-estimator     1.15.1         
tensorflow-gan           2.0.0          
tensorflow-gcs-config    2.3.0          
tensorflow-hub           0.8.0          
tensorflow-metadata      0.22.2         
tensorflow-privacy       0.2.2          
tensorflow-probability   0.7.0    

and the run the following code as guided

game = 'pong'
run_dir = get_run_dir(game, 1)
!python -m tensor2tensor.rl.evaluator \
  --loop_hparams_set=rlmb_long_stochastic_discrete \
  --loop_hparams=game=$game,eval_max_num_noops=8,eval_sampling_temps=[0.5] \
  --policy_dir=$run_dir/policy \
  --eval_metrics_dir=pong_pretrained \
  --debug_video_path=pong_pretrained \
  --num_debug_videos=4 

and another error arised

WARNING:tensorflow:
The TensorFlow contrib module will not be included in TensorFlow 2.0.
For more information, please see:
  * https://github.com/tensorflow/community/blob/master/rfcs/20180907-contrib-sunset.md
  * https://github.com/tensorflow/addons
  * https://github.com/tensorflow/io (for I/O related ops)
If you depend on functionality not listed there, please file an issue.

WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/tensor2tensor/utils/adafactor.py:27: The name tf.train.Optimizer is deprecated. Please use tf.compat.v1.train.Optimizer instead.

WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/tensor2tensor/utils/multistep_optimizer.py:32: The name tf.train.AdamOptimizer is deprecated. Please use tf.compat.v1.train.AdamOptimizer instead.

WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/tensor2tensor/models/research/glow_init_hook.py:25: The name tf.train.SessionRunHook is deprecated. Please use tf.estimator.SessionRunHook instead.

WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/tensor2tensor/models/research/neural_stack.py:51: The name tf.nn.rnn_cell.RNNCell is deprecated. Please use tf.compat.v1.nn.rnn_cell.RNNCell instead.

WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/tensor2tensor/utils/trainer_lib.py:111: The name tf.OptimizerOptions is deprecated. Please use tf.compat.v1.OptimizerOptions instead.

WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/tensor2tensor/utils/trainer_lib.py:111: The name tf.OptimizerOptions is deprecated. Please use tf.compat.v1.OptimizerOptions instead.

WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/tensorflow_gan/python/estimator/tpu_gan_estimator.py:42: The name tf.estimator.tpu.TPUEstimator is deprecated. Please use tf.compat.v1.estimator.tpu.TPUEstimator instead.

WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/tensorflow_gan/python/estimator/tpu_gan_estimator.py:42: The name tf.estimator.tpu.TPUEstimator is deprecated. Please use tf.compat.v1.estimator.tpu.TPUEstimator instead.

WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/dopamine/agents/dqn/dqn_agent.py:88: The name tf.train.RMSPropOptimizer is deprecated. Please use tf.compat.v1.train.RMSPropOptimizer instead.

WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/dopamine/agents/dqn/dqn_agent.py:88: The name tf.train.RMSPropOptimizer is deprecated. Please use tf.compat.v1.train.RMSPropOptimizer instead.

Traceback (most recent call last):
  File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/local/lib/python3.6/dist-packages/tensor2tensor/rl/evaluator.py", line 37, in <module>
    from tensor2tensor.rl import rl_utils
  File "/usr/local/lib/python3.6/dist-packages/tensor2tensor/rl/rl_utils.py", line 34, in <module>
    from tensor2tensor.rl.dopamine_connector import DQNLearner
  File "/usr/local/lib/python3.6/dist-packages/tensor2tensor/rl/dopamine_connector.py", line 393, in <module>
    class BatchRunner(run_experiment.Runner):
AttributeError: 'NoneType' object has no attribute 'Runner'
Q-ihang commented 4 years ago

On Colab, you can: 1.for the 'tensorflow.compat.v2' : try the command '%tensorflow_version 1.x' 2.for 'NoneType' object has no attribute 'Runner' : a. If class 'DQNLearner' is unnecessary in your project, comment corresponding 'import' line in 'rl_utils.py' file. b. or you try to find out why the absence of class 'run_experiment', most likely due to the installation of 'dopamine'.

Tracy-git commented 3 years ago

@Q-ihang your methed solve my problem thks