我已经从 github ( https://github.com/torch/demos/tree/master/train-a-digit-classifier ) 下载了 Torch 的演示。该代码在 CPU 模式下运行良好,但我想在 CUDA 6.5 的 GPU 模式下使用它。我已经使用 CUnn 和 CUtorch 安装了所有先决条件,并根据我找到的文档和教程,我添加了一些代码行以使其工作:
一开始:
require 'cunn'
require 'cutorch'
最后在模型声明之后:
model:cuda()
但是当我运行代码时,出现以下错误:
qlua: /home/ubuntu/Torch7/install/share/lua/5.1/nn/Container.lua:67:
In 1 module of nn.Sequential:
/home/ubuntu/Torch7/install/share/lua/5.1/nn/THNN.lua:109: bad argument #3 to 'v' (cannot convert 'struct THCudaTensor *' to 'struct THFloatTensor *')
stack traceback:
[C]: in function 'v'
/home/ubuntu/Torch7/install/share/lua/5.1/nn/THNN.lua:109: in function 'SpatialConvolutionMM_updateOutput'
...Torch7/install/share/lua/5.1/nn/SpatialConvolutionMM.lua:79: in function <...Torch7/install/share/lua/5.1/nn/SpatialConvolutionMM.lua:69>
[C]: in function 'xpcall'
/home/ubuntu/Torch7/install/share/lua/5.1/nn/Container.lua:63: in function 'rethrowErrors'
/home/ubuntu/Torch7/install/share/lua/5.1/nn/Sequential.lua:44: in function 'forward'
train-on-mnist.lua:227: in function 'opfunc'
/home/ubuntu/Torch7/install/share/lua/5.1/optim/sgd.lua:44: in function 'sgd'
train-on-mnist.lua:280: in function 'train'
train-on-mnist.lua:383: in main chunk
WARNING: If you see a stack trace below, it doesn't point to the place where this error occured. Please use only the one above.
stack traceback:
[C]: at 0xb6ae7bdd
[C]: in function 'error'
/home/ubuntu/Torch7/install/share/lua/5.1/nn/Container.lua:67: in function 'rethrowErrors'
/home/ubuntu/Torch7/install/share/lua/5.1/nn/Sequential.lua:44: in function 'forward'
train-on-mnist.lua:227: in function 'opfunc'
/home/ubuntu/Torch7/install/share/lua/5.1/optim/sgd.lua:44: in function 'sgd'
train-on-mnist.lua:280: in function 'train'
train-on-mnist.lua:383: in main chunk
编辑:
解决方案是使用脚本将数据、标签和标准转换为 Cuda,:cuda()
并且脚本运行良好。谢谢@lejlot