【问题标题】:How to predict using model generated by Torch?如何使用 Torch 生成的模型进行预测?
【发布时间】:2015-05-02 14:14:03
【问题描述】:

我已经执行了neuralnetwork_tutorial.lua。现在我有了模型,我想用我自己的一些手写图像来测试它。但是我尝试了很多方法来存储权重,现在使用torch save and load methods 存储完整的模型。

但是现在我尝试使用 model:forward(testImageTensor) 预测我自己的手写图像(转换为 28X28 DoubleTensor)

...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

【问题讨论】:

  • 在torch 中它是直截了当的,就像你试图做的那样。这似乎是使用“dp”包的副作用。也许“dp”的作者可以提供帮助。

标签: lua neural-network deep-learning torch


【解决方案1】:

你有两个选择。

一个。使用封装好的nn.Module转发你的torch.Tensor

mlp2 = mlp:toModule(datasource:trainSet():sub(1,2))
input = testImageTensor:view(1, 1, 32, 32)
output = mlp2:forward(input)

两个。将您的 torch.Tensor 封装到 dp.ImageView 并通过您的 dp.Model 转发:

inputView = dp.ImageView('bchw', testImageTensor:view(1, 1, 32, 32))
outputView = mlp:forward(inputView, dp.Carry{nSample=1})
output = outputView:forward('b')

【讨论】:

    猜你喜欢
    • 2021-07-01
    • 2020-08-24
    • 2020-06-24
    • 1970-01-01
    • 2016-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-11
    相关资源
    最近更新 更多