kazuto1011 / deeplab-pytorch

PyTorch re-implementation of DeepLab v2 on COCO-Stuff / PASCAL VOC datasets
MIT License
1.09k stars 282 forks source link

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

Closed Kitsunetic closed 4 years ago

Kitsunetic commented 4 years ago

https://github.com/kazuto1011/deeplab-pytorch/blob/4219467fa5de07985f834f1bd8c04c186dc8f6d8/libs/models/resnet.py#L110

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 commented 4 years ago

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 commented 4 years ago

OK thank you I understand.

I'll close this issue