models icon indicating copy to clipboard operation
models copied to clipboard

Object Detection API with TF2 AtributeError: module 'tensorflow' has no attribute 'contrib' from object_detection.builders import model_builder

Open grewe opened this issue 5 years ago • 7 comments

Prerequisites

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

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

1. The entire URL of the file you are using

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

2. Describe the bug

When trying to import model_builder using following line in my jupyter notebook: from object_detection.builders import model_builder

get the following error TF2 AtributeError: module 'tensorflow' has no attribute 'contrib'

Have searched and past discussion is this is error is due to Object Detection being attempted to run with TF2 instead of TF1 but, 10 days ago Object Detection API released in TF2.

3. Steps to reproduce

Steps to reproduce the behavior. Have Jupyter notebook, running tensorflow 2.3 have line of code specified above to import model_builder and fails as discussed

4. Expected behavior

Expect no error.

5. Additional context

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

6. System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Windows running Jupyter notebook in a conda environment
  • Mobile device name if the issue happens on a mobile device:
  • TensorFlow installed from (source or binary): (pip install)
  • TensorFlow version (use command below): 2.3.0-rc2
  • Python version: 3.7.4
  • Bazel version (if compiling from source):
  • GCC/Compiler version (if compiling from source):
  • CUDA/cuDNN version:
  • GPU model and memory:

grewe avatar Jul 22 '20 21:07 grewe

Do you happen to know which line is trying to reference tf.contrib?

jch1 avatar Jul 22 '20 23:07 jch1

below is complete error trace that is output in jupyter notebook

AttributeError Traceback (most recent call last) in 25 #NOTE: had to comment out the following two lines as had errors??? 26 #from object_detection.utils import colab_utils ---> 27 from object_detection.builders import model_builder 28 29 get_ipython().run_line_magic('matplotlib', 'inline')

C:\tensorflow\models\research\object_detection\builders\model_builder.py in 17 from object_detection.builders import anchor_generator_builder 18 from object_detection.builders import box_coder_builder ---> 19 from object_detection.builders import box_predictor_builder 20 from object_detection.builders import hyperparams_builder 21 from object_detection.builders import image_resizer_builder

C:\tensorflow\models\research\object_detection\builders\box_predictor_builder.py in 16 """Function to build box predictor from configuration.""" 17 ---> 18 from object_detection.core import box_predictor 19 from object_detection.protos import box_predictor_pb2 20

C:\tensorflow\models\research\object_detection\core\box_predictor.py in 34 from object_detection.utils import static_shape 35 ---> 36 slim = tf.contrib.slim 37 38 BOX_ENCODINGS = 'box_encodings'

AttributeError: module 'tensorflow' has no attribute 'contrib

grewe avatar Jul 22 '20 23:07 grewe

Have you made sure that the slim folder is on your python path? e,g,

export PYTHONPATH=$PYTHONPATH:/home/ubuntu/models/:/home/ubuntu/models/research/:/home/ubuntu/models/research/slim/://home/ubuntu/lugs/models/research/object_detection/

attianopp avatar Jul 23 '20 07:07 attianopp

Have you solved it? I have the same problem. I hope to get your help. @greweI

dreamitpossible1 avatar Jul 23 '20 13:07 dreamitpossible1

Hi, I have the exact same problem. Anyone managed to solve this?

TadaasCirk avatar Dec 09 '21 14:12 TadaasCirk

I had the same issue when using an anaconda environment 3.7.4 also with the pip distribution of tf_object_detection. I was able to get the object-detection API to work by fixing the dependencies, which for me meant scrapping the conda env and remaking it via this tutorial: https://tensorflow-object-detection-api-tutorial.readthedocs.io/en/latest/install.html

theodorhar avatar Jun 28 '22 03:06 theodorhar

Same issue here. Is "use TF 1.x" the only solution at the moment?? Thx

Full trace:

AttributeError Traceback (most recent call last) Cell In[1], line 47 45 import numpy as np 46 from object_detection.utils import config_util ---> 47 from object_detection.builders import model_builder 48 from object_detection.utils import label_map_util 49 from object_detection.utils import visualization_utils as viz_utils

File ~/miniconda3/envs/jup/lib/python3.12/site-packages/object_detection/builders/model_builder.py:22 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

File ~/miniconda3/envs/jup/lib/python3.12/site-packages/object_detection/builders/box_predictor_builder.py:20 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

File ~/miniconda3/envs/jup/lib/python3.12/site-packages/object_detection/predictors/convolutional_box_predictor.py:22 19 from object_detection.core import box_predictor 20 from object_detection.utils import static_shape ---> 22 slim = tf.contrib.slim 24 BOX_ENCODINGS = box_predictor.BOX_ENCODINGS 25 CLASS_PREDICTIONS_WITH_BACKGROUND = ( 26 box_predictor.CLASS_PREDICTIONS_WITH_BACKGROUND)

AttributeError: module 'tensorflow' has no attribute 'contrib'

masspern avatar Oct 28 '24 12:10 masspern