![](/img/trans.png)
[英]AttributeError: module 'tensorflow._api.v1.compat' has no attribute 'v2' For Tensorflow Object Detection API
[英]Tensorflow Object Detection AttributeError: module 'tensorflow._api.v1.compat' has no attribute 'v2'
当前运行 TF 1.13.2
我正在尝试训练我自己的对象检测模型。 尝试运行此命令后:
python model_main.py --logtostderr --model_dir=training/ --pipeline_config_path=traini
ng/faster_rcnn_inception_v2_pets.config
我收到此错误:
Traceback (most recent call last):
File "model_main.py", line 26, in <module>
from object_detection import model_lib
File "C:\Users\Admin\Anaconda3\envs\object_detection\lib\site-packages\object_detection-0.1-py3.6.egg\object_detection\model_lib.py", line 28, in <module>
from object_detection import exporter as exporter_lib
File "C:\Users\Admin\Anaconda3\envs\object_detection\lib\site-packages\object_detection-0.1-py3.6.egg\object_detection\exporter.py", line 24, in <module>
from object_detection.builders import model_builder
File "C:\Users\Admin\Anaconda3\envs\object_detection\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\Admin\Anaconda3\envs\object_detection\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\Admin\Anaconda3\envs\object_detection\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 "C:\Users\Admin\Desktop\ObjectDetection\models\research\object_detection\nets\mobilenet\mobilenet.py", line 399, in <module>
def global_pool(input_tensor, pool_op=tf.compat.v2.nn.avg_pool2d):
AttributeError: module 'tensorflow._api.v1.compat' has no attribute 'v2'
我需要保持在 TF 2.x 以下,因为 2.x 还不允许训练你自己的模型(根据 Gilbert Tanner 的对象检测教程)。 我在 TF 版本之间徘徊,并且在不同版本中遇到了类似的错误,即某些模块没有属性“v1”。 在任何一种情况下,我都不确定如何解决这个问题。
编辑:以下是我的环境的站点包:
Package Version Latest Version
absl-py 0.9.0 0.8.1
astor 0.8.1 0.8.0
biwrap 0.1.6
bleach 1.5.0 3.1.0
certifi 2019.11.28 2019.11.28
gast 0.3.3 0.3.2
grpcio 1.27.0 1.16.1
h5py 2.10.0 2.10.0
html5lib 1.000000 1.0.1
keras-applications 1.0.8 1.0.8
keras-preprocessing 1.1.0 1.1.0
markdown 3.1.1 3.1.1
mock 3.0.5 3.0.5
numpy 1.18.1 1.18.1
object-detection 0.100000
pandas 1.0.0 1.0.0
pillow 7.0.0 7.0.0
pip 20.0.2 20.0.2
protobuf 3.11.3 3.11.2
pycocotools 2.000000
python 3.6.10 3.8.1
python-dateutil 2.8.1 2.8.1
pytz 2019.300000 2019.300000
setuptools 39.1.0 45.1.0
six 1.14.0 1.14.0
sqlite 3.31.1 3.31.1
tensorboard 1.9.0 2.0.0
tensorflow 1.9.0 2.0.0
tensorflow-estimator 1.13.0 2.0.0
tensorflow-plot 0.3.0
tensorflow-tensorboard 1.5.1
termcolor 1.1.0 1.1.0
vc 14.100000 14.100000
vs2015_runtime 14.16.27012 14.16.27012
werkzeug 0.16.1 0.16.1
wheel 0.34.2 0.34.2
wincertstore 0.200000 0.200000
编辑:根据您在 TF1 应用程序中使用 TF2 设计的模型的经验。
你是从 Github 克隆模型的吗? 存储库基于最新的TF
您可以使用专为 1.13 设计的模型: https : //github.com/tensorflow/models/archive/v1.13.0.zip
重新启动以清除导出路径
cd 模型/模型-1.13.0/研究/
protoc object_detection/protos/*.proto --python_out=.
export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim
cd ../../..
python3 github/TensorFlow-object-detection-tutorial-master/5_part\ step\ by\ step\ custom\ object\ detection/train.py --logtostderr
--train_dir=training/ --pipeline_config_path=dataset/data1/faster_rcnn_inception_v2_coco_tf13.config
解决了问题 编辑:也在 GCP 和 Edge (jetson nano) 上进行了 TF 培训,如果您需要 moar 备份,请随时进行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.