使用Tensorflow Object Detection API进行宠物检测
API简介
一个很方便的物体检测模型训练、推理API, 很适合深度学习新手使用。建议搭配图书教程《深度学习图像识别技术:基于Tensorflow Object Detection API 与OpenVINO工作条件》食用
官方教程
这里官方是在Google Colab中进行的操作,便于学习,我们也使用Google Colab进行学习实践。
接下来我们跟着教程一步一步走,目前还只是在google环境中跑,没有什么bug,等换个环境再来记录bug
1. 环境安装
!pip install -U --pre tensorflow=="2.*"
!pip install tf_slim
!pip install pycocotools
2. git获取代码
import os
import pathlib
if "models" in pathlib.Path.cwd().parts:
while "models" in pathlib.Path.cwd().parts:
os.chdir('..')
elif not pathlib.Path('models').exists():
!git clone --depth 1 https://github.com/tensorflow/models
编译并安装目标检测包
%%bash
cd models/research/
protoc object_detection/protos/*.proto --python_out=.
%%bash
cd models/research
pip install .
3. 相关接口封装
- 导入相关模块
import numpy as np
import os
import six.moves.urllib as urllib
impor