Torch7与CUDA(CUnn和CUtorch) - 与MNIST的火炬演示

时间:2016-05-02 22:46:01

标签: lua torch mnist

我已经从github(https://github.com/torch/demos/tree/master/train-a-digit-classifier)下载了火炬的演示。该代码在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

0 个答案:

没有答案