文章作者:Tyan
博客:noahsnail.com ?|? CSDN ?|? 簡書
在使用Caffe模型進行圖像分類時嗡呼,通常使用的圖像大小為224 * 224
袱讹,如果改變輸入圖像的大小肝匆,有時候會碰到Check failed: shape[i] >= 0 (-1 vs. 0)
錯誤橘茉。
- 背景
使用ResNet-50進行圖像分類訓練嘲驾,輸入圖像的大小為160 *160
绢要。
- 錯誤
I1013 10:53:03.395526 76959 net.cpp:129] Top shape: 16 2048 5 5 (819200)
I1013 10:53:03.395531 76959 net.cpp:137] Memory required for data: 1889075264
I1013 10:53:03.395539 76959 layer_factory.hpp:77] Creating layer res5c_relu
I1013 10:53:03.395553 76959 net.cpp:84] Creating Layer res5c_relu
I1013 10:53:03.395567 76959 net.cpp:406] res5c_relu <- res5c
I1013 10:53:03.395594 76959 net.cpp:367] res5c_relu -> res5c (in-place)
I1013 10:53:03.395841 76959 net.cpp:122] Setting up res5c_relu
I1013 10:53:03.395855 76959 net.cpp:129] Top shape: 16 2048 5 5 (819200)
I1013 10:53:03.395861 76959 net.cpp:137] Memory required for data: 1892352064
I1013 10:53:03.395869 76959 layer_factory.hpp:77] Creating layer pool5
I1013 10:53:03.395900 76959 net.cpp:84] Creating Layer pool5
I1013 10:53:03.395908 76959 net.cpp:406] pool5 <- res5c
I1013 10:53:03.395931 76959 net.cpp:380] pool5 -> pool5
F1013 10:53:03.396807 76959 blob.cpp:32] Check failed: shape[i] >= 0 (-1 vs. 0)
*** Check failure stack trace: ***
@ 0x7fa7eef89e6d (unknown)
@ 0x7fa7eef8bced (unknown)
@ 0x7fa7eef89a5c (unknown)
@ 0x7fa7eef8c63e (unknown)
@ 0x7fa7f6141829 caffe::Blob<>::Reshape()
@ 0x7fa7f6141581 caffe::Blob<>::Reshape()
@ 0x7fa7f6200958 caffe::PoolingLayer<>::Reshape()
@ 0x7fa7f61b14d8 caffe::CuDNNPoolingLayer<>::Reshape()
@ 0x7fa7f6167d29 caffe::Layer<>::SetUp()
@ 0x7fa7f6240213 caffe::Net<>::Init()
@ 0x7fa7f623e7ea caffe::Net<>::Net()
@ 0x7fa7f62711e1 caffe::Solver<>::InitTrainNet()
@ 0x7fa7f6270a75 caffe::Solver<>::Init()
@ 0x7fa7f62705a7 caffe::Solver<>::Solver()
@ 0x7fa7f627dc66 caffe::SGDSolver<>::SGDSolver()
@ 0x7fa7f6287ab1 caffe::Creator_SGDSolver<>()
@ 0x4215f5 caffe::SolverRegistry<>::CreateSolver()
@ 0x41bdce train()
@ 0x41e167 main
@ 0x7fa7e20eeb35 __libc_start_main
@ 0x41aa69 (unknown)
- 解決方案
錯誤日志中可以看出問題出在pool5層
,它的輸入為Top shape: 16 2048 5 5 (819200)
蓄拣,即16 * 2048 * 5 * 5
扬虚,16
是batch_size
,2048
為channel
數(shù)量弯蚜,即kernel個數(shù),feature map大小為5 * 5
剃法,在prototxt中找到pool5層
碎捺,如下:
layer {
bottom: "res5c"
top: "pool5"
name: "pool5"
type: "Pooling"
pooling_param {
kernel_size: 7
stride: 1
pool: AVE
}
}
kernel size為7,比5大,因此將7改為5收厨,重新訓練晋柱,沒問題。