nelson1425 / EfficientAD

Unofficial implementation of EfficientAD https://arxiv.org/abs/2303.14535
https://arxiv.org/abs/2303.14535
Apache License 2.0
273 stars 72 forks source link

Purpose of padding #12

Closed AlessandroPolidori closed 1 year ago

AlessandroPolidori commented 1 year ago

https://github.com/nelson1425/EfficientAD/blob/fcab5146f84ae17597044ad5ddf1656ccf805401/efficientad.py#LL279C9-L279C75 I'm wondering why this padding is necessary. Can you help me?

nelson1425 commented 1 year ago

Hi, without this padding the segmentation metric will decrease very much because the segmentation pixels are not aligned anymore after the next line (map_combined = torch.nn.functional.interpolate(...)).

It is similar to applying 11x11 edge filter to 100x100 image. The result will be 90x90 image with detected edges. Resizing it to 100x100 would distort the detected edges. Instead you have to pad the 90x90 image with 5 pixels on each size.

In the case of EfficientAD, the patch size is 33, so 16 pixels padding on each border. The teacher has two layers with stride 2, so we need to divide the 16 pixels padding by 2 and again by 2, which gives us 4. So 4 pixels padding on each border for the output feature maps.

limaodaxia commented 8 months ago

Hi, without this padding the segmentation metric will decrease very much because the segmentation pixels are not aligned anymore after the next line (map_combined = torch.nn.functional.interpolate(...)).

It is similar to applying 11x11 edge filter to 100x100 image. The result will be 90x90 image with detected edges. Resizing it to 100x100 would distort the detected edges. Instead you have to pad the 90x90 image with 5 pixels on each size.

In the case of EfficientAD, the patch size is 33, so 16 pixels padding on each border. The teacher has two layers with stride 2, so we need to divide the 16 pixels padding by 2 and again by 2, which gives us 4. So 4 pixels padding on each border for the output feature maps.

image

how caculate these values? how can I know what size should I pad? For example, when it comes to these origin sizes, what size should I pad if I want to resize 56×56 to these origin sizes?