kazuto1011 / deeplab-pytorch

PyTorch re-implementation of DeepLab v2 on COCO-Stuff / PASCAL VOC datasets

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

Kitsunetic opened this issue · comments

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.

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.

OK thank you I understand.

I'll close this issue