Ubuntu20.04配置objection_detection

版本说明

本文用到的object_detection版本是2022年3月的版本。python版本是3.8.140。tensorflow版本是2.8.0。

配置过程

首先在GitHub上下载object_detection的文件包,下载网址:https://github.com/tensorflow/models
下载后解压到没有中文的路径下,我直接放到主文件夹下,如图所示。
Ubuntu20.04配置objection_detection_第1张图片
解压后需要安装protobuf和protobuf-compiler函数库,这里可以用国内镜像源,会快一些,我使用的清华源,指令如下:

pip3 install -i https://pypi.mirrors.ustc.edu.cn/simple protobuf
sudo apt install protobuf-compiler

安完protobuf和protobuf-compiler后,还需将~/models-master/research/object_detection/protos文件夹下的文件转译成.py文件。

protoc object_detection/protos/*.proto --python_out=. 

还需要配置COCO API,下载地址:https://github.com/cocodataset/cocoapi
下载后直接解压即可,我放在了主文件夹下,如图所示。
Ubuntu20.04配置objection_detection_第2张图片
然后进行cocoapi-master/PythonAPI,如图所示。
Ubuntu20.04配置objection_detection_第3张图片
在打开Makefile文件将其里面的Python改成Python3.
Ubuntu20.04配置objection_detection_第4张图片
Ubuntu20.04配置objection_detection_第5张图片
修改后点击保存。最后在~/cocoapi-master/PythonAPI文件夹下执行make命令。

lgb@vip:~/cocoapi-master/PythonAPI$ make

Ubuntu20.04配置objection_detection_第6张图片
执行make后,显示下图式样即为编译成功。
Ubuntu20.04配置objection_detection_第7张图片
执行make时有时会出现如下错误:
Ubuntu20.04配置objection_detection_第8张图片
此时需要安装cython函数库。

pip3 install -i https://pypi.mirrors.ustc.edu.cn/simple cython

编译成功后将pycocotools文件复制到~/models-master/research文件夹下。
Ubuntu20.04配置objection_detection_第9张图片
Ubuntu20.04配置objection_detection_第10张图片
执行上述步骤后还需将models-master/research/object_detection/packages/tf2/setup.py文件复制到:models-master/research文件下。
Ubuntu20.04配置objection_detection_第11张图片
Ubuntu20.04配置objection_detection_第12张图片
完成上述步骤就完成了objection_detection的配置,接下来就可以测试objection_detection是否安装成功,进入~/models-master/research文件夹内,在命令行打开执行model_builder_tf2_test.py文件,如果安装的tensorflow1.x运行model_builder_tf1_test.py。

gb@vip:~/models-master/research$ python object_detection/builders/model_builder_tf2_test.py

我安装是会出现ModuleNotFoundError: No module named 'object_detection’错误,错误如下。
Ubuntu20.04配置objection_detection_第13张图片
出现这种情况,需要进行python的函数库文件夹(我的电脑实在:/lib/python3/dist-packages)新建tensorflow_path.pth文件。
Ubuntu20.04配置objection_detection_第14张图片
文件里面放的是research和slim两个文件夹的路径。
在这里插入图片描述
然后继续执行model_builder_tf2_test.py文件

gb@vip:~/models-master/research$ python object_detection/builders/model_builder_tf2_test.py

这里我的电脑还会出现ModuleNotFoundError: No module named 'tf_slim’错误,此时只需安装tf.slim函数库即可
Ubuntu20.04配置objection_detection_第15张图片

pip3 install -i https://pypi.mirrors.ustc.edu.cn/simple tf.slim

继续执行model_builder_tf2_test.py文件,我的电脑继续出现ModuleNotFoundError: No module named 'scipy’错误,此时秩序安装scipy函数库即可。
Ubuntu20.04配置objection_detection_第16张图片

pip3 install -i https://pypi.mirrors.ustc.edu.cn/simple scipy

继续执行model_builder_tf2_test.py文件,我的电脑继续出现ModuleNotFoundError: No module named 'tensorflow_io’错误,此时秩序安装tensorflow_io函数库即可。
Ubuntu20.04配置objection_detection_第17张图片

pip3 install -i https://pypi.mirrors.ustc.edu.cn/simple tensorflow_io

继续执行model_builder_tf2_test.py文件,我的电脑继续出现ModuleNotFoundError: No module named 'official’错误,此时秩序安装tf-models-official函数库即可。
Ubuntu20.04配置objection_detection_第18张图片

pip3 install -i https://pypi.mirrors.ustc.edu.cn/simple tf-models-official

继续执行model_builder_tf2_test.py文件,我的电脑没有出现错误,如有错误按照提示,缺啥函数,安装好即可。执行model_builder_tf2_test.py文件出现如图式样即为object_detection配置成功。
Ubuntu20.04配置objection_detection_第19张图片

你可能感兴趣的:(python)