abcnn-keras icon indicating copy to clipboard operation
abcnn-keras copied to clipboard

Conv2d wrong output shape

Open gewoonrik opened this issue 7 years ago • 3 comments

shouldn't this line: nb_filter=nb_filter, nb_row=filter_width, nb_col=embed_dimensions, activation="tanh", border_mode="valid",

be nb_filter=1, nb_row=filter_width, nb_col=embed_dimensions, activation="tanh", border_mode="valid",

to get an output shape of (1,steps, embed_dimensions) which can then be reshaped to: (steps, embed_dimensions) and then processed as conv1d? same for conv_right

gewoonrik avatar May 05 '17 18:05 gewoonrik

We need the ability to treat different channels, which 1-D convolutions can't do. We apply the 2-D convolution in a way that it is actually one dimensional, that's why there is a strange looking reshape after.. I'll try and have a close look at what you mean, but on first glance I do think this is correct.

phdowling avatar May 05 '17 21:05 phdowling

When I ran the code as is, I got an error on this line

I thought it was a padding issue, so I changed border_mode to same instead of valid for conv_left and conv_right. This resulted in an error on the reshapes, which I fixed by changing nb_filter to 1 for the Convolution2Ds

But I'm not sure if this works as intended.

gewoonrik avatar May 09 '17 14:05 gewoonrik

I think this error is a zero padding issue.

When it try to pad zeros for wide convolution on this line, it actually pads zeros on the shape of channel.

If you print the shape of left_embed_padded, it will be (?, 2+(filter_width - 1)*2, left_seq_len, embed_dimensions). However, it should be (?, 2, left_seq_len+(filter_width - 1)*2, embed_dimensions).

You can change

left_embed_padded = ZeroPadding2D((filter_width - 1, 0))(left_embed)
right_embed_padded = ZeroPadding2D((filter_width - 1, 0))(right_embed)

to

left_embed_padded = ZeroPadding2D((filter_width - 1, 0), data_format = 'channels_first')(left_embed)
right_embed_padded = ZeroPadding2D((filter_width - 1, 0), data_format = 'channels_first')(right_embed)

It will fix this error.

kjes89011 avatar Mar 15 '18 14:03 kjes89011