1

使用Torch Caffe 绑定。我想对Flickr Style 示例进行预测。我有经过训练的模型和下面的代码。我如何必须更改代码才能使其工作?

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])

现在要输出的是具有 20 倍 NaN 值的 FloatTensor [torch.FloatTensor,尺寸为 20x1x1]。

4

0 回答 0