Justin
Justin

Reputation: 137

Tensorflow Object Detection AttributeError: module 'tensorflow._api.v1.compat' has no attribute 'v2'

Currently running TF 1.13.2

I'm trying to train my own object detection model. After trying to run this command:

python model_main.py --logtostderr --model_dir=training/ --pipeline_config_path=traini
ng/faster_rcnn_inception_v2_pets.config

I get this error:

Traceback (most recent call last):
  File "model_main.py", line 26, in <module>
    from object_detection import model_lib
  File "C:\Users\Admin\Anaconda3\envs\object_detection\lib\site-packages\object_detection-0.1-py3.6.egg\object_detection\model_lib.py", line 28, in <module>
    from object_detection import exporter as exporter_lib
  File "C:\Users\Admin\Anaconda3\envs\object_detection\lib\site-packages\object_detection-0.1-py3.6.egg\object_detection\exporter.py", line 24, in <module>
    from object_detection.builders import model_builder
  File "C:\Users\Admin\Anaconda3\envs\object_detection\lib\site-packages\object_detection-0.1-py3.6.egg\object_detection\builders\model_builder.py", line 47, in <module>
    from object_detection.models.ssd_mobilenet_edgetpu_feature_extractor import SSDMobileNetEdgeTPUFeatureExtractor
  File "C:\Users\Admin\Anaconda3\envs\object_detection\lib\site-packages\object_detection-0.1-py3.6.egg\object_detection\models\ssd_mobilenet_edgetpu_feature_extractor.py", line
 19, in <module>
    from object_detection.models import ssd_mobilenet_v3_feature_extractor
  File "C:\Users\Admin\Anaconda3\envs\object_detection\lib\site-packages\object_detection-0.1-py3.6.egg\object_detection\models\ssd_mobilenet_v3_feature_extractor.py", line 25,
in <module>
    from nets.mobilenet import mobilenet
  File "C:\Users\Admin\Desktop\ObjectDetection\models\research\object_detection\nets\mobilenet\mobilenet.py", line 399, in <module>
    def global_pool(input_tensor, pool_op=tf.compat.v2.nn.avg_pool2d):
AttributeError: module 'tensorflow._api.v1.compat' has no attribute 'v2'

I need to stay below TF 2.x because 2.x does not yet allow for training your own model (according to Gilbert Tanner's object detection tutorial). I've bounced around between TF versions and I've gotten similar errors in different versions that some module has no attribute 'v1'. In either case, I'm not sure at all how to fix this.

Edit: Here are the site-packages for my environment:

Package Version Latest Version
absl-py 0.9.0   0.8.1
astor   0.8.1   0.8.0
biwrap  0.1.6   
bleach  1.5.0   3.1.0
certifi 2019.11.28  2019.11.28
gast    0.3.3   0.3.2
grpcio  1.27.0  1.16.1
h5py    2.10.0  2.10.0
html5lib    1.000000    1.0.1
keras-applications  1.0.8   1.0.8
keras-preprocessing 1.1.0   1.1.0
markdown    3.1.1   3.1.1
mock    3.0.5   3.0.5
numpy   1.18.1  1.18.1
object-detection    0.100000    
pandas  1.0.0   1.0.0
pillow  7.0.0   7.0.0
pip 20.0.2  20.0.2
protobuf    3.11.3  3.11.2
pycocotools 2.000000    
python  3.6.10  3.8.1
python-dateutil 2.8.1   2.8.1
pytz    2019.300000 2019.300000
setuptools  39.1.0  45.1.0
six 1.14.0  1.14.0
sqlite  3.31.1  3.31.1
tensorboard 1.9.0   2.0.0
tensorflow  1.9.0   2.0.0
tensorflow-estimator    1.13.0  2.0.0
tensorflow-plot 0.3.0   
tensorflow-tensorboard  1.5.1   
termcolor   1.1.0   1.1.0
vc  14.100000   14.100000
vs2015_runtime  14.16.27012 14.16.27012
werkzeug    0.16.1  0.16.1
wheel   0.34.2  0.34.2
wincertstore    0.200000    0.200000

Upvotes: 0

Views: 1644

Answers (1)

ETdecode
ETdecode

Reputation: 425

EDIT: from experience you are using a TF2 designed model in a TF1 application.

Did you clone the models from Github? The repository is based on the latest TF

You can use the models designed for 1.13 specifically: https://github.com/tensorflow/models/archive/v1.13.0.zip

reboot to clear EXPORT PATH

cd models/models-1.13.0/research/

protoc object_detection/protos/*.proto --python_out=.

export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim

cd ../../..

python3 github/TensorFlow-object-detection-tutorial-master/5_part\ step\ by\ step\ custom\ object\ detection/train.py --logtostderr
--train_dir=training/ --pipeline_config_path=dataset/data1/faster_rcnn_inception_v2_coco_tf13.config

Solved the issue EDIT: made the TF training on GCP and on Edge (jetson nano) too, feel free to up if you need moar backup.

source

Upvotes: 1

Related Questions