liuzhuang13 / DenseNet

Densely Connected Convolutional Networks, In CVPR 2017 (Best Paper Award).
BSD 3-Clause "New" or "Revised" License
4.71k stars 1.07k forks source link

error using CAddTable and ConcatTable #11

Closed brisker closed 7 years ago

brisker commented 7 years ago

There are a lot of residual blocks in your densenet, I tried to build a few in my own network, but why torch just gives me errors when using CAddTable and ConcatTable. Could you please give some advice? The code I use is here:

    a=image.load('test.png')
    input=torch.Tensor(1,3,60,60)
    input[1]=a
    input=input:cuda()
local conv_block_1 = nn.Sequential()
conv_block_1:add(cudnn.SpatialConvolution(3, 16, 5, 5, 1, 1, 2, 2))--  ,(60+2*2-5)/1+1=60
conv_block_1:add(cudnn.SpatialBatchNormalization(16))
conv_block_1:add(cudnn.ReLU(true))

local conv_block_2 = nn.Sequential()
conv_block_2:add(cudnn.SpatialConvolution(16, 32, 5, 5, 1, 1, 2, 2)) -- (60+2*2-5)/1+1=60
conv_block_2:add(cudnn.SpatialBatchNormalization(32))
conv_block_2:add(cudnn.ReLU(true))

local conv_block_3 = nn.Sequential()
conv_block_3:add(cudnn.SpatialConvolution(32, 16, 5, 5, 1, 1, 2, 2)) -- (60+2*2-5)/1+1=60
conv_block_3:add(cudnn.SpatialBatchNormalization(16))
conv_block_3:add(cudnn.ReLU(true))

local concat_block_1 = nn.ConcatTable()
concat_block_1:add(conv_block_1)  ----
concat_block_1:add(conv_block_3 )

local add_block_1 = nn.Sequential()
add_block_1:add(concat_block_1)
add_block_1:add(nn.CAddTable(true))
add_block_1:add(cudnn.ReLU(true))

local model=nn.Sequential()
model:add(conv_block_1)

model:add(conv_block_2)
    model:add(conv_block_3)
   model:add(add_block_1)
    model:cuda()
    model:forward(input)

and the error reads like this: In 4 module of nn.Sequential: In 1 module of nn.Sequential: In 1 module of nn.ConcatTable: In 1 module of nn.Sequential: ...torch/install/share/lua/5.1/cudnn/SpatialConvolution.lua:102: input has to contain: 3 feature maps, but received input of size: 1 x 16 x 60 x 60 stack traceback:

liuzhuang13 commented 7 years ago

Sorry for the late response

Your model-add_block_1-concat_block_1's first convolution layer needs a input of 3 feature maps, but it seems your model-conv_block_3 feeds it with a output of 16 feature maps.

Also, there are no "residual-blocks" in our DenseNet. There are only identity and concatenation, but not addition.

Thanks!