facebookarchive / fb.resnet.torch

Torch implementation of ResNet from http://arxiv.org/abs/1512.03385 and training scripts
Other
2.29k stars 664 forks source link

converting linear layer to convolutional #173

Closed bjuncek closed 7 years ago

bjuncek commented 7 years ago

When I try to convert the final nn.linear(nFeatures, 1000) layer be convolutional (in order to help me handle multi-dimensional inputs later on), I get a bunch of errors. Is it possible to change it only in the model file (which would mean that I'm messing up my input sizes), or are there additional changes that I'd need to make to the code to make it work?

For reference, I am replacing it with model:add(Convolution(nFeatures,1000, 3,3,1,1)) or would I need to do

colesbury commented 7 years ago

Yes, you can replace the last layer with a convolution, but you probably need to also remove the nn.View and your kernel size should be 1x1 instead of 3x3.

bjuncek commented 7 years ago

Thanks! That seems to break the computeScore in train.lua, however adding nn.view(1000) (or whatever the nClasses is seems to fix it).