Skip to content

Commit bcd7fbb

Browse files
authored
Consider even block sizes in drop block 2d
1 parent f52c4f1 commit bcd7fbb

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

torchvision/ops/drop_block.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ def drop_block2d(
4242
noise.bernoulli_(gamma)
4343

4444
noise = F.pad(noise, [block_size // 2] * 4, value=0)
45-
noise = F.max_pool2d(noise, stride=(1, 1), kernel_size=(block_size, block_size), padding=block_size // 2)
45+
left_pad = right_pad = block_size // 2
46+
if left_pad > 0 and block_size % 2 == 0:
47+
left_pad -= 1
48+
noise = F.pad(noise, pad=(left_pad, right_pad, left_pad, right_pad))
49+
noise = F.max_pool2d(noise, stride=1, kernel_size=block_size)
4650
noise = 1 - noise
4751
normalize_scale = noise.numel() / (eps + noise.sum())
4852
if inplace:

0 commit comments

Comments
 (0)