Models: AttributeError: module 'tensorflow_core.compat.v1' has no attribute 'contrib'

Created on 25 Jul 2020  路  8Comments  路  Source: tensorflow/models

Prerequisites

Please answer the following questions for yourself before submitting an issue.

  • [ ] I am using the latest TensorFlow Model Garden release and TensorFlow 2.
  • [ ] I am reporting the issue to the correct repository. (Model Garden official or research directory)
  • [ ] I checked to make sure that this issue has not been filed already.

1. The entire URL of the file you are using

https://github.com/tensorflow/models/tree/master/official/...

2. Describe the bug

2020-07-25 10:07:11.122491: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll
WARNING:tensorflow:From C:\Users\dw\Anaconda3\envs\TF2.2\libsite-packages\tensorflow_core\python\compat\v2_compat.py:88: disable_resource_variables (from tensorflow.python.ops.variable_scope) is deprecated and will be removed in a future version.
Instructions for updating:
non-resource variables are not supported in the long term
Traceback (most recent call last):
File "model_main_tf2.py", line 31, in
from object_detection import model_lib_v2
File "D:\tf_train\models\research\object_detection\model_lib_v2.py", line 27, in
from object_detection import eval_util
File "D:\tf_train\models\research\object_detection\eval_util.py", line 36, in
slim = tf.contrib.slim
AttributeError: module 'tensorflow_core.compat.v1' has no attribute 'contrib'

3. Steps to reproduce

python model_main_tf2.py --model_dir=training --pipeline_config_path=training/center_net_hourglass104_1024x1024_coco17_tpu-32.config --alsologtostderr

4. Expected behavior

Start training the model

5. Additional context

(TF2.1) D:\tf_train\workspaces\my_training_demo1>python model_main_tf2.py --model_dir=training --pipeline_config_path=training/center_net_hourglass104_1024x1024_coco17_tpu-32.config --alsologtostderr
2020-07-25 10:13:58.091313: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll
WARNING:tensorflow:From C:\Users\dw\Anaconda3\envs\TF2.2\libsite-packages\tensorflow_core\python\compat\v2_compat.py:88: disable_resource_variables (from tensorflow.python.ops.variable_scope) is deprecated and will be removed in a future version.
Instructions for updating:
non-resource variables are not supported in the long term
Traceback (most recent call last):
File "model_main_tf2.py", line 31, in
from object_detection import model_lib_v2
File "D:\tf_train\models\research\object_detection\model_lib_v2.py", line 27, in
from object_detection import eval_util
File "D:\tf_train\models\research\object_detection\eval_util.py", line 36, in
slim = tf.contrib.slim
AttributeError: module 'tensorflow_core.compat.v1' has no attribute 'contrib'

6. System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04):Windows 10 professional workstation
  • TensorFlow installed from (source or binary)锛歛naconda
  • TensorFlow version (use command below):tensorflow-gpu=2.1
  • Python version:3.6.10
  • CUDA/cuDNN version: cudatoolkit=10.1 cudnn=7.6.5
  • GPU model and memory: GTX2070, 39.8G

unknown 2.1.0

research awaiting response bug

Most helpful comment

Same issue as NitinSaini18. I get the same error in spite of using :
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()

All 8 comments

@dreamitpossible1

contrib module is no longer available in TensorFlow 2.0, but you can use with this;
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()

or uninstall TensorFlow and install oldest version with this;
pip install tensorflow==1.14

Detailed information; https://www.tensorflow.org/guide/migrate

Tensorflow Core released a utility to convert your TF 1.x scripts to TF2.0 which can be found here:
https://www.tensorflow.org/guide/upgrade

Thanks!

Automatically closing due to lack of recent activity. Please update the issue when new information becomes available, and we will reopen the issue. Thanks!

@ravikyram import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
I used this code but I am facing same error
AttributeError: module 'tensorflow' has no attribute 'compat'

Same issue as NitinSaini18. I get the same error in spite of using :
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()

I got the same problem as @NitinSaini18 and @richarnaik
Were you able to solve it?

Same issue still even after import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()

@Gaurav37 What I did at the end was switching from Python 3.8 to Python3.7 (since Tensorflow 1.x is not working with Python 3.8) and the use Tensorflow 1.x (in my case 1.14.0) instead of 2.x

@richarnaik @Kuehlhausvogel I have the same problem. I can solved using it.

https://stackoverflow.com/questions/61066142/unable-to-use-tf-contrib

Was this page helpful?
0 / 5 - 0 ratings