ImportError:无法从“tensorflow.python.framework”导入名称“device_spec”

Posted

技术标签:

【中文标题】ImportError:无法从“tensorflow.python.framework”导入名称“device_spec”【英文标题】:ImportError: cannot import name 'device_spec' from 'tensorflow.python.framework' 【发布时间】:2020-10-10 16:23:01 【问题描述】:

当我尝试跑步时 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(最近一次调用):文件“train.py”,第 51 行,在 从 object_detection.builders 导入 dataset_builder 文件“C:\tensorflow1\models\research\object_detection\builders\dataset_builder.py”, 第 33 行,在 从 object_detection.builders 导入 decoder_builder 文件“C:\tensorflow1\models\research\object_detection\builders\decoder_builder.py”, 第 25 行,在 从 object_detection.data_decoders 导入 tf_example_decoder 文件 "C:\tensorflow1\models\research\object_detection\data_decoders\tf_example_decoder.py", 第 28 行,在 从 tf_slim 导入 tfexample_decoder 作为 slim_example_decoder 文件 "C:\Users\user\anaconda3\envs\tensorflow1\lib\site-packages\tf_slim_init_.py", 第 25 行,在 从 tf_slim.layers 导入 * 文件 "C:\Users\user\anaconda3\envs\tensorflow1\lib\site-packages\tf_slim\layers_init_.py", 第 25 行,在 从 tf_slim.layers.layers 导入 * 文件“C:\Users\user\anaconda3\envs\tensorflow1\lib\site-packages\tf_slim\layers\layers.py”, 第 30 行,在 从 tf_slim.ops 导入变量文件“C:\Users\user\anaconda3\envs\tensorflow1\lib\site-packages\tf_slim\ops\variables.py”, 第 27 行,在 from tensorflow.python.framework import device_spec as tf_device ImportError: cannot import name 'device_spec'

【问题讨论】:

device_spec 包含在 Tensorflow 2 中,可能您正在使用 Tensorflow1,这就是您没有它的原因。尝试将 tensorflow 更新到最新版本。 【参考方案1】:

编辑 -> 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 版本。

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

【讨论】:

以上是关于ImportError:无法从“tensorflow.python.framework”导入名称“device_spec”的主要内容,如果未能解决你的问题,请参考以下文章

python aiorpc:“ImportError:无法从'aiorpc.server'导入名称'RPCServer'”

ImportError:无法从“变压器”导入名称“AutoModelWithLMHead”

ImportError:无法从“matplotlib.mlab”导入名称“PCA”

ImportError:无法从“sklearn.externals”导入名称“joblib”

ImportError:无法从“sklearn.externals”导入名称“joblib”

ImportError:无法从“google.cloud”(未知位置)导入名称“bigquery”