使用Torch Caffe Binding。我想对Flickr Style example进行预测。我有训练有素的模型和下面的代码。我如何更改代码才能使其正常工作?
require 'caffe'
require 'image'
-- test flickr_style single image
-- configuaration
caffe_path = '/home/user/caffe/'
data_path = caffe_path..'data/flickr_style/images/'
file_name = data_path..'614893901_c9ed490f80.jpg'
-- caffe in CPU mode
caffe.Net.setModeCPU()
-- initialize net
net = caffe.Net(caffe_path..'models/finetune_flickr_style/deploy.prototxt', caffe_path..'models/finetune_flickr_style/finetune_flickr_style.caffemodel','test')
-- load and resize image
input = torch.FloatTensor(10,3,227,227)
img = image.load(file_name,3,'float')
img = image.scale(img,227,227)
for i=1,3 do
for j=1,32 do
for k=1,32 do
input[1][i][j][k] = img[i][j][k]
end
end
end
-- predict result
output = net:forward(input)
print(output[1])
y,j = torch.max(output[1],1)
print('Class: ', j[1][1][1] , y[1][1][1])
现在输出的是FloatTensor [尺寸为20x1x1的torch.FloatTensor],其NaN值为20倍。