如何使 Torch Caffe Lua中的Flickr Style示例工作?

使用[Torch Caffe Binding](https://github.com/szagoruyko/torch-caffe-binding) 。我想在[Flickr样式示例](http://caffe.berkeleyvision.org/gathered/examples/finetune_flickr_style.html)上进行预测。我已经拥有了训练好的模型和下面的代码。我如何更改代码才能使其工作?

require 'caffe'
require 'image'

-- 测试 Flickr 样式单个图像
-- 配置
caffe_path = '/home/user/caffe/'
data_path = caffe_path..'data/flickr_style/images/'
file_name = data_path..'614893901_c9ed490f80.jpg'

-- Caffe 运行在 CPU 模式
caffe.Net.setModeCPU()

-- 初始化网络
net = caffe.Net(caffe_path..'models/finetune_flickr_style/deploy.prototxt', caffe_path..'models/finetune_flickr_style/finetune_flickr_style.caffemodel','test')

-- 加载并调整图像大小
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

-- 预测结果
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],其中有20个NaN值。

点赞