导入错误:无法使用对象检测 API 从“tensorflow.python.tpu”导入名称“feature_column_v2”

Rod*_*osp 5 python object-detection tensorflow

我正在尝试使用 tensorflow 的对象检测 API,并且在调用model_main.py.

ImportError: cannot import name 'feature_column_v2' from 'tensorflow.python.tpu'
Run Code Online (Sandbox Code Playgroud)

这发生在我打电话后:

python model_main.py --logtostderr --train_dir=training/ --pipeline_config_path=training/ssd_mobilenet_v1_pets.config
Run Code Online (Sandbox Code Playgroud)

完整追溯:

Traceback (most recent call last):
  File "model_main.py", line 26, in <module>
    from object_detection import model_lib
  File "C:\Users\Rodolfo\AppData\Local\Programs\Python\Python37\lib\site-packages\object_detection-0.1-py3.7.egg\object_detection\model_lib.py", line 28, in <module>
    from object_detection import eval_util
  File "C:\Users\Rodolfo\AppData\Local\Programs\Python\Python37\lib\site-packages\object_detection-0.1-py3.7.egg\object_detection\eval_util.py", line 35, in <module>
    slim = tf.contrib.slim
  File "C:\Users\Rodolfo\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\util\lazy_loader.py", line 62, in __getattr__
    module = self._load()
  File "C:\Users\Rodolfo\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\util\lazy_loader.py", line 45, in _load
    module = importlib.import_module(self.__name__)
  File "C:\Users\Rodolfo\AppData\Local\Programs\Python\Python37\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "C:\Users\Rodolfo\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\contrib\__init__.py", line 33, in <module>
    from tensorflow.contrib import compiler
  File "C:\Users\Rodolfo\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\contrib\compiler\__init__.py", line 22, in <module>
    from tensorflow.contrib.compiler import xla
  File "C:\Users\Rodolfo\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\contrib\compiler\xla.py", line 22, in <module>
    from tensorflow.python.estimator import model_fn as model_fn_lib
  File "C:\Users\Rodolfo\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\estimator\__init__.py", line 26, in <module>
    from tensorflow_estimator.python import estimator
  File "C:\Users\Rodolfo\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_estimator\python\estimator\__init__.py", line 25, in <module>
    import tensorflow_estimator.python.estimator.estimator_lib
  File "C:\Users\Rodolfo\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_estimator\python\estimator\estimator_lib.py", line 69, in <module>
    from tensorflow_estimator.python.estimator.tpu.tpu_estimator import TPUEstimator
  File "C:\Users\Rodolfo\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_estimator\python\estimator\tpu\tpu_estimator.py", line 83, in <module>
    from tensorflow_estimator.python.estimator import estimator as estimator_lib
  File "C:\Users\Rodolfo\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_estimator\__init__.py", line 8, in <module>
    from tensorflow_estimator._api.v1 import estimator
  File "C:\Users\Rodolfo\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_estimator\_api\v1\estimator\__init__.py", line 11, in <module>
    from tensorflow_estimator._api.v1.estimator import tpu
  File "C:\Users\Rodolfo\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_estimator\_api\v1\estimator\tpu\__init__.py", line 8, in <module>
    from tensorflow_estimator._api.v1.estimator.tpu import experimental
  File "C:\Users\Rodolfo\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_estimator\_api\v1\estimator\tpu\experimental\__init__.py", line 8, in <module>
    from tensorflow_estimator.python.estimator.tpu._tpu_estimator_embedding import EmbeddingConfigSpec
  File "C:\Users\Rodolfo\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_estimator\python\estimator\tpu\_tpu_estimator_embedding.py", line 32, in <module>
    from tensorflow.python.tpu import feature_column_v2 as tpu_fc_v2
ImportError: cannot import name 'feature_column_v2' from 'tensorflow.python.tpu' (C:\Users\Rodolfo\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\tpu\__init__.py)
Run Code Online (Sandbox Code Playgroud)

我的training文件夹里面是labelmap和配置文件,配置文件中正确指定了tf记录。

管道配置文件中的路径:

train_input_reader: {
  tf_record_input_reader {
    input_path: "data/train.record"
  }
  label_map_path: "training/object-detection.pbtxt"
}

eval_input_reader: {
  tf_record_input_reader {
    input_path: "data/test.record"
  }
  label_map_path: "training/object-detection.pbtxt"
  shuffle: false
  num_readers: 1
}
Run Code Online (Sandbox Code Playgroud)

我在 Windows 10 上运行所有东西,使用 Python 3.7 并且 API 似乎工作正常,因为我运行了测试文件并且测试运行没有任何问题。我还运行了对象检测示例 jupyter notebook,它也有效。

Gha*_*nem 5

将您的 tensorflow 版本升级到 1.14(至少)。