SSD(Single Shot MultiBox Detector):因为数据集中图像通道数不对导致的训练异常

今天在开始做SSD训练的时候,报了一个错误 导致训练无法 进行下去:

OpenCV Error: Assertion failed ((scn == 3 || scn == 4) && (depth == CV_8U || depth == CV_32F)) in cvtColor, file /build/opencv-SviWsf/opencv-2.4.9.1+dfsg/modules/imgproc/src/color.cpp, line 3959
terminate called after throwing an instance of ‘cv::Exception’
what(): /build/opencv-SviWsf/opencv-2.4.9.1+dfsg/modules/imgproc/src/color.cpp:3959: error: (-215) (scn == 3 || scn == 4) && (depth == CV_8U || depth == CV_32F) in function cvtColor
* Aborted at 1492071248 (unix time) try “date -d @1492071248” if you are using GNU date *
PC: @ 0x7f1497764428 gsignal
* SIGABRT (@0x3e800000985) received by PID 2437 (TID 0x7f1455438700) from PID 2437; stack trace: *
@ 0x7f14977644b0 (unknown)
@ 0x7f1497764428 gsignal
@ 0x7f149776602a abort
@ 0x7f1497d9d84d __gnu_cxx::__verbose_terminate_handler()
@ 0x7f1497d9b6b6 (unknown)
@ 0x7f1497d9b701 std::terminate()
@ 0x7f1497d9b919 __cxa_throw
@ 0x7f1487838c66 cv::error()
@ 0x7f1489de2f91 cv::cvtColor()
@ 0x7f149967b817 caffe::AdjustSaturation()
@ 0x7f149967fc0b caffe::RandomSaturation()
@ 0x7f14996802ef caffe::ApplyDistort()
@ 0x7f149982f743 caffe::DataTransformer<>::DistortImage()
@ 0x7f14997a5096 caffe::AnnotatedDataLayer<>::load_batch()
@ 0x7f14997fbecb caffe::BasePrefetchingDataLayer<>::InternalThreadEntry()
@ 0x7f1499685d45 caffe::InternalThread::entry()
@ 0x7f149751a5d5 (unknown)
@ 0x7f1496dd36ba start_thread
@ 0x7f149783582d clone
@ 0x0 (unknown)
Aborted (core dumped)

看这个错误信息只知道是opencv的一个断言错误 ,因为 没glog输出信息,无从知道是从哪个源文件抛出的。但是看到这个assert表达式(scn == 3 || scn == 4) && (depth == CV_8U || depth == CV_32F)
感觉可能与数据集的图像通道数有关,记得faster rcnn ,ssd这多数的模型都要求是3通道RGB的图像,会不会我生成的数据集中有1通道或4通道的图像呢?
于是在数据集Annotations文件夹下执行grep搜索

guyadong@gyd-u16:~/data/VOCdevkit/VOC2007/Annotations$ grep \<depth\>1 *
  • 1

果然发现有一些depth为1的图像(也就是灰度图像)在里面。重新修改了数据集生成代码(我们自己有一个图像数据标注及训练数据生成系统,java代码),只提取depth为3的图像生成VOC2007数据集,再执重新执行create_list.sh,create_data.sh生成lmdb,再开始训练 ,则问题解决 :

cd caffe-ssd
./data/VOC2007/create_list.sh
./data/VOC2007/create_data.sh
python ./examples/ssd/ssd_pascal.py
  • 1
  • 2
  • 3
  • 4

另外,在训练时glog输出如下的错误 ,也是同样的原因 :

annotated_data_layer.cpp:205
CHECK(std::equal(top_shape.begin() + 1, top_shape.begin() + 4,
              shape.begin() + 1)
  • 1
  • 2
  • 3

相关文章
相关标签/搜索