tensorflow / models

Models and examples built with TensorFlow
Other
77.25k stars 45.75k forks source link

Got an AttributeError: module 'tensorflow' has no attribute 'contrib' when following Tensorflow 2.0 object detection tutorial #9666

Open weekenddeveloper opened 3 years ago

weekenddeveloper commented 3 years ago

Prerequisites

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

1. The entire URL of the file you are using

http://download.tensorflow.org/models/object_detection/tf2/20200711/faster_rcnn_resnet101_v1_640x640_coco17_tpu-8.tar.gz

2. Describe the bug

I am using tensorflow 2.0 and tried to follow the object detection tutorial (https://tensorflow-object-detection-api-tutorial.readthedocs.io/en/latest/auto_examples/object_detection_camera.html). However, when I tried to load the model, I got an Attribute error.

I did the research online and got the answer that you have to use tensorflow 1.4 to make the object detection work. and contrib has been deprecated in tensorflow 2.0.

I am confused that the tutorial for tensorflow 2.0 object detection api will require tensorflow 1.x??

3. Steps to reproduce

Use tensorflow 2.0, follow the TF 2.0 object detection tutorial, and when you load the model, you will get the issue.

4. Expected behavior

model get loaded correctly.

5. Additional context

Include any logs that would be helpful to diagnose the problem.

AttributeError Traceback (most recent call last)

in 8 from object_detection.utils import config_util 9 from object_detection.utils import visualization_utils as viz_utils ---> 10 from object_detection.builders import model_builder 11 12 tf.get_logger().setLevel('ERROR') # Suppress TensorFlow logging (2) ~\Anaconda3\envs\tf20\lib\site-packages\object_detection\builders\model_builder.py in 20 from object_detection.builders import anchor_generator_builder 21 from object_detection.builders import box_coder_builder ---> 22 from object_detection.builders import box_predictor_builder 23 from object_detection.builders import hyperparams_builder 24 from object_detection.builders import image_resizer_builder ~\Anaconda3\envs\tf20\lib\site-packages\object_detection\builders\box_predictor_builder.py in 18 import collections 19 import tensorflow as tf ---> 20 from object_detection.predictors import convolutional_box_predictor 21 from object_detection.predictors import convolutional_keras_box_predictor 22 from object_detection.predictors import mask_rcnn_box_predictor ~\Anaconda3\envs\tf20\lib\site-packages\object_detection\predictors\convolutional_box_predictor.py in 20 from object_detection.utils import static_shape 21 ---> 22 slim = tf.contrib.slim 23 24 BOX_ENCODINGS = box_predictor.BOX_ENCODINGS AttributeError: module 'tensorflow' has no attribute 'contrib' ## 6. System information - OS Platform and Distribution (e.g., Linux Ubuntu 16.04): windows 10 - Mobile device name if the issue happens on a mobile device: - TensorFlow installed from (source or binary): anaconda - TensorFlow version (use command below): 2.0 - Python version: 3.7 - Bazel version (if compiling from source): - GCC/Compiler version (if compiling from source): - CUDA/cuDNN version: - GPU model and memory:
elvinest commented 3 years ago

I had the same issue.

kaisark commented 3 years ago

Same Issue: Bug in Tutorial for TF2?

$PYTHONPATH: /home/useraccount/.local/lib/python3.6/site-packages:/home/useraccount/models/research/slim:/home/useraccount/models/research:/home/useraccount/models

(py36dl) useraccount@nano:~/models/research$ python object_detection/builders/model_builder_test.py 2021-04-08 21:29:05.738693: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.10.2 Traceback (most recent call last): File "object_detection/builders/model_builder_test.py", line 23, in from object_detection.builders import model_builder File "/home/useraccount/models/research/object_detection/builders/model_builder.py", line 22, in from object_detection.builders import box_predictor_builder File "/home/useraccount/models/research/object_detection/builders/box_predictor_builder.py", line 20, in from object_detection.predictors import convolutional_box_predictor File "/home/useraccount/models/research/object_detection/predictors/convolutional_box_predictor.py", line 22, in slim = tf.contrib.slim AttributeError: module 'tensorflow' has no attribute 'contrib'

Dueschen commented 3 years ago

Same issue. I was running https://github.com/tensorflow/models/blob/master/research/slim/train_image_classifier.py and the same error occured.