我正在尝试将我的卷积神经网络建立在以下教程的基础上:
https://github.com/torch/tutorials/tree/master/2_supervised
问题是我的图像与教程中使用的图像尺寸不同。(3x200x200)。我也只有两节课。
以下是我所做的更改:
更改要在 1_data.lua 中加载的数据集。
nfeats = 3
width = 200
height = 200
ninputs = nfeats*width*height
和
nclass,noutputs
在 3_loss.lua 和 4_train.lua 中。
我的模型与教程中训练的模型相同。为方便起见,我将代码放在下面:
model = nn.Sequential()
-- stage 1 : filter bank -> squashing -> L2 pooling -> normalization
model:add(nn.SpatialConvolutionMM(nfeats, nstates[1], filtsize, filtsize))
model:add(nn.Tanh())
model:add(nn.SpatialLPPooling(nstates[1],2,poolsize,poolsize,poolsize,poolsize))
model:add(nn.SpatialSubtractiveNormalization(nstates[1], normkernel))
-- stage 2 : filter bank -> squashing -> L2 pooling -> normalization
model:add(nn.SpatialConvolutionMM(nstates[1], nstates[2], filtsize, filtsize))
model:add(nn.Tanh())
model:add(nn.SpatialLPPooling(nstates[2],2,poolsize,poolsize,poolsize,poolsize))
model:add(nn.SpatialSubtractiveNormalization(nstates[2], normkernel))
-- stage 3 : standard 2-layer neural network
model:add(nn.Reshape(nstates[2]*filtsize*filtsize))
model:add(nn.Linear(nstates[2]*filtsize*filtsize, nstates[3]))
model:add(nn.Tanh())
model:add(nn.Linear(nstates[3], noutputs))
运行 doall.lua 文件时出现以下错误:
==> online epoch # 1 [batchSize = 1]
/home/torch/install/share/lua/5.1/torch/Tensor.lua:462: Wrong size for view. Input size: 64x47x47. Output size: 64x1600
stack traceback:
[C]: in function 'error'
/home/torch/install/share/lua/5.1/torch/Tensor.lua:462: in function 'view'
/home/torch/install/share/lua/5.1/nn/Reshape.lua:49: in function 'updateOutput'
/home/torch/install/share/lua/5.1/nn/Sequential.lua:29: in function 'forward'
4_train.lua:160: in function 'opfunc'
/home/torch/install/share/lua/5.1/optim/sgd.lua:43: in function 'optimMethod'
4_train.lua:184: in function 'train'
doall.lua:77: in main chunk
[C]: in function 'dofile'
[string "_RESULT={dofile('doall.lua' )}"]:1: in main chunk
[C]: in function 'xpcall'
/home/torch/install/share/lua/5.1/trepl/init.lua:630: in function 'repl'
.../torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:185: in main chunk
[C]: at 0x00406670
我已经坚持了一天多。请帮忙。