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

Question about why resnet._Stem.pool have padding #91

Closed
Kitsunetic opened this issue Sep 22, 2020 · 2 comments
Closed

Question about why resnet._Stem.pool have padding #91

Kitsunetic opened this issue Sep 22, 2020 · 2 comments

Comments

@Kitsunetic
Copy link

self.add_module("pool", nn.MaxPool2d(3, 2, 1, ceil_mode=True))

During tests with Deeplab, I found input image size is not divisible by output image size.
The output image size is input_size // 8 + 1.

For example,

# input: torch.Size([1, 3, 1280, 720])
# output: torch.Size([1, 21, 161, 91])

I found why input size is not divisible by output is because of the padding in resnet._Stem.pool layer.

# original
self.pool = nn.MaxPool2d(3, 2, 1, ceil_mode=True)

# result
# input: torch.Size([1, 3, 1280, 720])
# output: torch.Size([1, 21, 161, 91])

# padding = 0
self.pool = nn.MaxPool2d(3, 2, 0, ceil_mode=True)

# result
# input: torch.Size([1, 3, 1280, 720])
# output: torch.Size([1, 21, 160, 90])

I think there is reason why _Stem.pool have padding, but cannot understand why.

@kazuto1011
Copy link
Owner

The padding=1 is in the typical ResNet architectures. Indivisible behavior is caused by the ceil_mode=True and is expected as in DeepLab. To avoid this, please switch to ceil_mode=False.

@Kitsunetic
Copy link
Author

OK thank you I understand.

I'll close this issue

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