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


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

command this error pops out.

–logtostderr –train_dir=training/ –pipeline_config_path=training/faster_rcnn_inception_v2_pets.config Traceback (most recent call last): File "", line 51, in

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


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.