Tensorflow Object Detection API 使用步骤

需要安装的库有:
pandas
针对PIL 缺失, 需要装的包,
conda install Pillow

matplotlib

装了matplotlib,可能因为一会儿用 pip装包,一会儿conda,导致 numpy被降级
出现

module compiled against API version 0xc but this version of numpy is 0xb

这样的错误

又使用

pip install numpy --upgrade

进行升级!

pycocotools
注意: 这个make 用的python 环境 要和 后面执行训练用的 python 版本一致,否则
No module named ‘pycocotools._mask’
也就是说,后面如果是用 conda环境中 tensorflow 和 python,
这里也要 切换到 同样的环境中执行!!!

git clone https://github.com/cocodataset/cocoapi.git
cd cocoapi/PythonAPI
make
cp -r pycocotools <path_to_tensorflow>/models/research/

The Tensorflow Object Detection API uses Protobufs to configure model and training parameters. Before the framework can be used, the Protobuf libraries must be compiled. This should be done by running the following command from the tensorflow/models/research/ directory:

# From tensorflow/models/research/
protoc object_detection/protos/*.proto --python_out=.

环境变量设置,这个是必要的
不然出现

ImportError: No module named 'nets'

类似这样的问题

# From tensorflow/models/research/
export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim

训练步骤:
1 将标注数据转为一定的CSV格式,

2 执行 python 文件, 分别生成 train.record 和 test.record
用的代码来自:https://blog.csdn.net/RobinTomps/article/details/78115628
注意,这个python 代码中 函数 class_text_to_int 中 要修改 关于 类别名称的代码,。还有就是 图片文件扩展名 要根据实际情况进行 修改

3 建一个 label_map.pbtxt 文件, 这个文件是 类别名称 和 ID 的对应关系。id序号注意与前面创建CSV文件时保持一致,从1开始

4 拷贝一个 ssd_mobilenet_v1_coco.config 或者其他模型 配置文件, 修改里面的东西,主要有以下 几项:
num_classes: 1
train_input_reader 中 input_path 和 label_map_path
eval_input_reader中 input_path 和 label_map_path

如果使用预训练模型,那么from_detection_checkpoint 为true,
并且设置fine_tune_checkpoint 的路径

5 执行 model_main.py 开始训练

# From the tensorflow/models/research/ directory
python object_detection/model_main.py --pipeline_config_path=/home/bst-cd/panghaiyan/DataSet/demo_data/trainsets/faster_rcnn_resnet50_coco.config --model_dir=object_detection/training --num_train_steps=50000 --num_eval_steps=2000 --alsologtostderr

预测的步骤:
1 先要 导出模型, 这个 使用 脚本完成,注意命令行参数 涉及到的路径
2 修改 导出模型的路径PATH_TO_FROZEN_GRAPH
3 修改 标签路径
4 PATH_TO_TEST_IMAGES_DIR,这是测试图片路径,注意是否需要修改图像扩展名
5 cv2.imwrite(‘test_dataset/’ 这是结果保存路径
6 data.to_csv(‘detectRes/test_dataset2.csv’, 检测结果保存

遇到的问题,训练了一些次数以后,报错
ValueError: Tensor conversion requested dtype string for Tensor with dtype float32: ‘Tensor(“arg0:0”, shape=(), dtype=float32, device=/device:CPU:0)’

这是 eval 相关配置不对导致的,比如 eval_input_reader 中的record 文件路径没写对!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值