我已经执行了神经网络_tutorial.lua https://github.com/nicholas-leonard/dp/blob/master/examples/neuralnetwork_tutorial.lua。现在我有了模型,我想用一些我自己的手写图像来测试它。但我通过存储权重尝试了很多方法,现在通过使用存储完整的模型火炬保存和加载方法 https://github.com/torch/torch7/blob/master/doc/serialization.md.
然而现在我尝试使用预测我自己的手写图像(转换为 28X28 DoubleTensor)model:forward(testImageTensor)
...ches/torch/install/share/lua/5.1/dp/model/sequential.lua:30: attempt to index local 'carry' (a nil value)
stack traceback:
...ches/torch/install/share/lua/5.1/dp/model/sequential.lua:30: in function '_forward'
...s/torches/torch/install/share/lua/5.1/dp/model/model.lua:60: in function 'forward'
[string "model:forward(testImageTensor)"]:1: in main chunk
[C]: in function 'xpcall'
...aries/torches/torch/install/share/lua/5.1/trepl/init.lua:588: in function 'repl'
...ches/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:185: in main chunk
[C]: at 0x0804d650
你有两个选择。
一。使用封装的nn.模块 https://github.com/torch/nn/blob/master/doc/module.md#module转发您的火炬张量 https://github.com/torch/torch7/blob/master/doc/tensor.md#tensor:
mlp2 = mlp:toModule(datasource:trainSet():sub(1,2))
input = testImageTensor:view(1, 1, 32, 32)
output = mlp2:forward(input)
二。将你的 torch.Tensor 封装成dp.ImageView http://dp.readthedocs.org/en/latest/view/index.html#dp.ImageView并通过您的转发dp.Model http://dp.readthedocs.org/en/latest/model/index.html#dp.Model :
inputView = dp.ImageView('bchw', testImageTensor:view(1, 1, 32, 32))
outputView = mlp:forward(inputView, dp.Carry{nSample=1})
output = outputView:forward('b')
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)