torch / torch7

http://torch.ch
Other
8.97k stars 2.38k forks source link

Need understanding on forward pass of deep 1D convolution network #1128

Closed Jamesswiz closed 6 years ago

Jamesswiz commented 6 years ago

Hello All, I am new to this field, so I need clarity on how the outputs from one layer are passed to second layer. Here is a part of code I am using: params: nInput-input size, KW-kernel width, dW-kernel shift, mp-maxpooling stride, nf-no of filters

    local nout1= math.floor((nInput-params.kW1)/params.dW1)+1
local nout2=math.floor(nout1/params.mp1);
    local nout3= math.floor((nout2-params.kW2)/params.dW2)+1

net:add(nn.TemporalConvolution(1,params.nf1,params.kW1,params.dW1));
net:add(nn.TemporalMaxPooling(params.mp1,params.mp1))
net:add(nn.HardTanh());
net:add(nn.TemporalConvolution(params.nf1,params.nf2,params.kW2,params.dW2));
    net:add(nn.Reshape(nout3*params.nf2));

so First convolution layer takes 'nInput' and outputs a matrix of size (nf1 x nout1) Max-pooling reduces the output matrix as of size (nf1 x nout2)
Second convolution layer takes matrix (nf1 x nout2) as input and outputs a matrix of size (nf2 x nout3) for each of the nout2 columns of input matrix.

Then how the output is of size (nout3 x nf2) after reshaping/flattering? shouldn't it be (nout2 x nout3 x nf2). ?

any help would be appreciated?

thanks