【发布时间】:2017-10-30 22:45:00
【问题描述】:
我正在尝试从 caffe 模型动物园运行预训练的 googlenet 模型(无微调)。模型和deploy.prototxt都是从https://github.com/BVLC/caffe/tree/master/models/bvlc_googlenet下载的
下面是我正在使用的代码:
net = caffe.Net('deploy.prototxt', 'bvlc_googlenet.caffemodel', caffe.TEST)
net.blobs['data'].reshape(1,3,224,224)
image_path = '1.png'
img = caffe.io.load_image(image_path)
img = caffe.io.resize( img, (224, 224, 3) )
# mean subtraction
img[0,:,:] -= 104 / 255.0
img[1,:,:] -= 117 / 255.0
img[2,:,:] -= 123 / 255.0
# 224,224,3 -> 3,224,224
img = np.transpose(img, (2, 0, 1))
out = net.forward(data=np.array([img]))['prob']
print(np.argmax(out))
看起来模型加载正常,但无论输入如何,它总是输出相同的类 (885)。可能是什么原因?
UPD:实际上,同样的问题也适用于其他模型,无论我是否是指减法,只是总是检测到的类发生了一些变化。
【问题讨论】:
标签: python deep-learning caffe pycaffe