ImportError: cannot import name 'device_spec' from 'tensorflow.python.framework'

Issue

When i try to run
python train.py --logtostderr --train_dir=training/ --pipeline_config_path=training/faster_rcnn_inception_v2_pets.config

command this error pops out.
(tensorflow1.13)

C:\tensorflow1\models\research\object_detection>python train.py
–logtostderr –train_dir=training/ –pipeline_config_path=training/faster_rcnn_inception_v2_pets.config Traceback (most recent call last): File "train.py", line 51, in

from object_detection.builders import dataset_builder File "C:\tensorflow1\models\research\object_detection\builders\dataset_builder.py",
line 33, in
from object_detection.builders import decoder_builder File "C:\tensorflow1\models\research\object_detection\builders\decoder_builder.py",
line 25, in
from object_detection.data_decoders import tf_example_decoder File
"C:\tensorflow1\models\research\object_detection\data_decoders\tf_example_decoder.py",
line 28, in
from tf_slim import tfexample_decoder as slim_example_decoder File
"C:\Users\user\anaconda3\envs\tensorflow1\lib\site-packages\tf_slim_init_.py",
line 25, in
from tf_slim.layers import * File "C:\Users\user\anaconda3\envs\tensorflow1\lib\site-packages\tf_slim\layers_init_.py",
line 25, in
from tf_slim.layers.layers import * File "C:\Users\user\anaconda3\envs\tensorflow1\lib\site-packages\tf_slim\layers\layers.py",
line 30, in
from tf_slim.ops import variables File "C:\Users\user\anaconda3\envs\tensorflow1\lib\site-packages\tf_slim\ops\variables.py",
line 27, in
from tensorflow.python.framework import device_spec as tf_device ImportError: cannot import name ‘device_spec’

Solution

EDIT -> The TF OD API now supports TF2

FRCNN is one of the supported models. Soooooooo, update your TF Models version and you should be good to go 🙂

You can check out the updated TF OD API here.


Do you know what version of the Object Detection API you are using?

You probably have one of the versions which targets TF2. Looks like you are training FRCNN which isn’t supported on TF2 yet – hence the issue!

You can find an older version of the TF Models API here. Try release v1.13 which targets TF 1.13.

The OD API will probably be migrated to TF2 in future but don’t hold your breath.

Answered By – mackdelany

Answer Checked By – Marie Seifert (AngularFixing Admin)

Leave a Reply

Your email address will not be published.