Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Input and output of convolutional layer have different lengths #3

Open
caolingyu opened this issue Apr 18, 2018 · 1 comment
Open

Comments

@caolingyu
Copy link

Hi there,

I read your paper and you mentioned that you used padding to ensure the input and output of convolutional layer have the same length. However, in the code you set padding=int(kernel_size/2), which can not ensure that. For example, the input is 111 and the kernel_size is 4, the input after padding would be 0011100 and after the length of output would be 4.

I googled and found that pytorch seems to have no similar function as tensorflow's 'same' padding for convolutional layer. Is there any workaround to achieve this?

Thanks a lot.

@jamesmullenbach
Copy link
Owner

Yeah, the lack of “same” padding is frustrating - you are right, technically, with this code the convolution output size will only be the same for odd width filters. One solution for even width filters is to use torch.nn.functional.pad, which lets you manually pad zeros on either side of a Variable in any dimension. In practice I’m not sure it will make a noticeable difference though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants