使用Tensorflow objection detection API出错解决办法

本来想使用tensorflow2.0以上版本的,但是tensorflow models2.0以上的代码有问题(截至本文时间,之后google应该会修改),因此用的tensorflow1.14。因为每个人电脑环境不一样,直接运行会报很多错误。下面给出我在运行过程遇到的错误以及解决办法。
首先把models给clone下来,可以参考这个。然后运行models/research/object_detection/object_detection_tutorial.ipynb,代码里面用训练和好的通用目标检测模型进行检测,运行的时候发现代码里面用plt.imshow显示不出图片,于是参考了models2.2里面的代码用IPython.display显示出图片。

1、ModuleNotFoundError: No module named ‘object_detection’

需在models/research/目录下执行:

python setup.py install

参考:
https://www.jianshu.com/p/df42f49e7e9c

2、ImportError: No module named ‘nets’

运行setup.py文件,将slim中所有的模块加载。

python setup.py build
python setup.py install

参考:
https://blog.csdn.net/qidailiming1994/article/details/94584621
https://blog.csdn.net/huixingshao/article/details/80466158

3、ImportError: No module named ‘pycocotools’

直接安装pycocotools

pip install pycocotools

4、Message type “object_detection.protos.SsdFeatureExtractor” has no field named "bat

将pipeline.config中的batch_norm_trainable: true删除就可以。
参考:
https://blog.csdn.net/weixin_38383877/article/details/103788723
https://www.cnblogs.com/hezhiqiangTS/p/11233745.html

5、TypeError: can’t pickle dict_values objects

在安装目录site-packages\object_detection-0.1-py3.6.egg\object_detection\model_lib.py中,将category_index.values() 变成list(category_index.values()).
参考:
https://github.com/tensorflow/models/issues/4780
https://www.jianshu.com/p/30301ecd6350
https://blog.csdn.net/qq_27882063/article/details/86094951

6、TypeError: ‘numpy.float64’ object cannot be interpreted as an integer

这个报错在训练过程中出现,导致训练停止,这是numpy版本问题,解决办法:将numpy降级为1.17.5版本可解决。
先用

pip show numpy

查看numpy版本;
再用

pip install -U numpy==1.17.5

降低numpy的版本

7、修改训练次数

在配置文件,比如ssd_mobilenet_v2.config中,改变num_steps的次数即可。

你可能感兴趣的:(使用Tensorflow objection detection API出错解决办法)