如何使用Torch7进行预测

我还在熟悉 Torch,目前为止一切顺利。但是我遇到了一个死胡同,不知道该怎么解决:如何让 Torch7(或更具体地说是 dp 库)对单个输入进行评估并返回预测的输出?

这是我的设置(基本上是 dp 示例):

点赞
用户49985
用户49985

你有两个选择。

第一种。使用封装的nn.Module来将你的torch.Tensor前向传递:

mlp = model:toModule(datasource:trainSet():sub(1,2))
mlp:float()
input = torch.FloatTensor(1, 1, 32, 32) -- 用你的输入替换这里
output = mlp:forward(input)

第二种。将你的torch.Tensor封装到dp.ImageView中,并通过你的dp.Model进行前向传递:

input = torch.FloatTensor(1, 1, 32, 32) -- 用你的输入替换这里
inputView = dp.ImageView('bchw', input)
outputView = mlp:forward(inputView, dp.Carry{nSample=1})
output = outputView:forward('b')
2015-04-01 20:45:20