错误:
ValueError: Mean Shape incompatible with input shape.
原因:
在classify.py中,调入mean.npy文件(该文件由mean.binaryproto生成,转换代码 convertmean.py). mean.npy中的数据大小与实际输入数据不同,这可能是由于在training data 准备时,有不同尺寸照片未被resize造成的。
解决方法:
修改文件 [caffe目录]/python/caffe/io.py
找到语句:
if ms != self.inputs[in_][1:]:
raise ValueError('Mean shape incompatible with input shape.')
修改为:
if ms != self.inputs[in_][1:]:
print(self.inputs[in_])
in_shape = self.inputs[in_][1:]
m_min, m_max = mean.min(), mean.max()
normal_mean = (mean - m_min) / (m_max - m_min)
mean = resize_image(normal_mean.transpose((1,2,0)),in_shape[1:]).transpose((2,0,1)) *(m_max - m_min) + m_min
#raise ValueError('Mean shape incompatible with input shape.')
Reference:
http://stackoverflow.com/questions/29842935/mean-shape-incompatible-with-input-shape-caffe-classification-error-in-io-py
http://blog.csdn.net/gzljss/article/details/45849013