如何使用Torch生成的模型进行预测? [英] How to predict using model generated by Torch?

查看:1383
本文介绍了如何使用Torch生成的模型进行预测?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经执行了 neuralnetwork_tutorial.lua .现在有了模型,我想用一些自己的手写图像对其进行测试.但是我尝试了多种方法来存储权重,现在通过使用

I have executed the neuralnetwork_tutorial.lua. Now that I have the model, I would like to test it with some of my own handwritten images. But I have tried many ways by storing the weights, and now by storing the complete model using torch save and load methods.

但是现在我尝试使用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.Module 转发您的 torch.Tensor :

One. Use the encapsulated nn.Module to forward your torch.Tensor:

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

两个.将炬管张量封装到 dp.ImageView 中,然后通过您的 dp.Model 转发:

Two. Encapsulate your torch.Tensor into a dp.ImageView and forward that through your dp.Model :

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

这篇关于如何使用Torch生成的模型进行预测?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆