python调用caffe接口进行classify时提示Mean shape incompatible with input shape错误的解决方法

python调用caffe接口进行classify时提示Mean shape incompatible with input shape错误的解决方法:


第一种:将 mean = np.load(args.mean_file),改成 mean = np.load(args.mean_file).mean(1).mean(1)


第二种:修改caffe中python接口的源代码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.')
并重新编译caffe-python接口

猜你喜欢

转载自blog.csdn.net/eagelangel/article/details/51009682