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

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

当我尝试 运行 python train.py --logtostderr --train_dir=training/ --pipeline_config_path=training/faster_rcnn_inception_v2_pets.config

命令弹出这个错误。 (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'

编辑 -> TF OD API 现在支持 TF2

FRCNN 是受支持的模型之一。 Soooooooo,更新您的 TF 模型版本,您应该可以开始了:)

您可以查看 updated TF OD API here


您知道您使用的是哪个版本的对象检测API吗?

您可能有一个针对 TF2 的版本。看来您正在训练 TF2 尚不支持的 FRCNN - 因此出现问题!

您可以找到旧版本的 TF Models API here。尝试发布针对 TF 1.13 的 v1.13。

ODAPI可能会在未来but don't hold your breath迁移到TF2。