tensorflow / models

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

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

Open grewe opened 4 years ago

grewe commented 4 years ago

Prerequisites

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

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

jch1 commented 4 years ago

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

grewe commented 4 years ago

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
attianopp commented 4 years ago

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/

dreamitpossible1 commented 4 years ago

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

TadaasCirk commented 2 years ago

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

theodorhar commented 2 years ago

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

masspern commented 1 month ago

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'