最近仔细研究了下SSD相关的几个demo文件,在这里做一个简要的记录。
大神weiliu89提供的Caffe/examples/ssd下提供了很多demo程序,常用的有以下这么几个。
关于配置Caffe-SSD请参看官方文档或我之前的笔记,不过我之前的教程是基于ROS的。
使用ssd_detect.cpp
生成可执行程序:
注:C++程序不自动显示label
对ssd_detect.cpp进行编译,生成可执行二进制文件,使用ssd_detect.bin接口程序(路径:caffe/build/examples/ssd/),检测image或video;
1
2
3
4
5
6
7build/examples/ssd/ssd_detect.bin models/VGGNet/VOC0712/SSD_300x300/deploy.prototxt \
models/VGGNet/VOC0712/SSD_300x300/VGG_VOC0712_SSD_300x300_iter_120000.caffemodel \
examples/videos/test.txt --file_type video \
--out_file output.txt \
--confidence_threshold 0.4 #检测视频,阈值为0.4并保存结果
# 一定要注意上述路径,最易出错
# 注:若出现错误,请将换行符删除使用examples/ssd/plot_detections.py,对ssd_detect.cpp的输出文件,绘制检测结果。
1
2
3
4
5
6python examples/ssd/plot_detections.py examples/images/result.txt \
/home/catkin_ws/src/roc_caffe/caffe \
--labelmap-file data/VOC0712/labelmap_voc.prototxt \
--save-dir examples/
# 一定要注意上述路径,最易出错
# 注:若出现错误,请将换行符删除
作为类来调用
将ssd_detect.cpp改写为一个头文件(譬如:Detector.h),然后进行调用。
使用ssd_detect.py
1 | # 先进入caffe主路径,譬如我的路径 |
Debugs
1 | # Bug |