AttributeError: module 'tensorflow._api.v1.compat' has no attribute 'v2' For Tensorflow Object Detection API

AttributeError: module 'tensorflow._api.v1.compat' has no attribute 'v2' For Tensorflow Object Detection API

我正在 Python 上研究 Tensorflow 对象检测 API。我正在训练自定义对象检测算法,当我尝试从 Models/object_detection 的旧文件夹中 运行 train.py 时,使用的预训练模型是 ssd_mobilenet_v1_pets.config 我得到了这个特定错误

 Traceback (most recent call last):
  File "train.py", line 48, in <module>
    from object_detection.builders import model_builder
  File "C:\Users\Captain\AppData\Local\Programs\Python\Python36\lib\site-packages\object_detection-0.1-py3.6.egg\object_detection\builders\model_builder.py", line 47, in <module>
    from object_detection.models.ssd_mobilenet_edgetpu_feature_extractor import SSDMobileNetEdgeTPUFeatureExtractor
  File "C:\Users\Captain\AppData\Local\Programs\Python\Python36\lib\site-packages\object_detection-0.1-py3.6.egg\object_detection\models\ssd_mobilenet_edgetpu_feature_extractor.py", line 19, in <module>
    from object_detection.models import ssd_mobilenet_v3_feature_extractor
  File "C:\Users\Captain\AppData\Local\Programs\Python\Python36\lib\site-packages\object_detection-0.1-py3.6.egg\object_detection\models\ssd_mobilenet_v3_feature_extractor.py", line 25, in <module>
    from nets.mobilenet import mobilenet
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 656, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 626, in _load_backward_compatible
  File "C:\Users\Captain\AppData\Local\Programs\Python\Python36\lib\site-packages\slim-0.1-py3.6.egg\nets\mobilenet\mobilenet.py", line 399, in <module>
AttributeError: module 'tensorflow._api.v1.compat' has no attribute 'v2'

我有

  1. 张量流 1.13.2
  2. Python 3.6
  3. Windows 10

这是我在 windows 命令提示符下尝试 运行 的命令。

python train.py --logtostderr --train_dir=Users/Captain/Desktop/ANPR V1/ --pipeline_config_path=Users/Captain/Desktop/ANPR V1/ssd_inception_v2_coco.config

我想可能是因为我使用的是其他型号所以也尝试了这个命令

python train.py --logtostderr --train_dir=Users/Captain/Desktop/ANPR V1/ --pipeline_config_path=Users/Captain/Desktop/ANPR V1/ssd_mobilenet_v1_pets.config

但我得到了同样的错误

我遇到了同样的问题。如果您下载了 tensorflow models then try downloading this tensorflow models of version 1.13.0 的最新存储库而不是最新的存储库,因为您正在使用 Tensorflow 1.13.2。 它解决了我的问题。