Skip to content

Commit f519aff

Browse files
authored
Fix dedode when calling detect() with padding correctly handled (kornia#3147)
* Instead of turing off the padding, fix it when using only detect(). * Fix when turn off padding in forward(), h, w are undecalred. Signed-off-by: wq <wq@sightp.com> --------- Signed-off-by: wq <wq@sightp.com>
1 parent f036121 commit f519aff

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

kornia/feature/dedode/dedode.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ def forward(
105105
if apply_imagenet_normalization:
106106
images = self.normalizer(images)
107107
B, C, H, W = images.shape
108+
h, w = images.shape[2:]
108109
if pad_if_not_divisible:
109-
h, w = images.shape[2:]
110110
pd_h = 14 - h % 14 if h % 14 > 0 else 0
111111
pd_w = 14 - w % 14 if w % 14 > 0 else 0
112112
images = torch.nn.functional.pad(images, (0, pd_w, 0, pd_h), value=0.0)
@@ -142,15 +142,17 @@ def detect(
142142
"""
143143
KORNIA_CHECK_SHAPE(images, ["B", "3", "H", "W"])
144144
self.train(False)
145+
B, C, H, W = images.shape
145146
if pad_if_not_divisible:
146147
h, w = images.shape[2:]
147148
pd_h = 14 - h % 14 if h % 14 > 0 else 0
148149
pd_w = 14 - w % 14 if w % 14 > 0 else 0
149150
images = torch.nn.functional.pad(images, (0, pd_w, 0, pd_h), value=0.0)
150151
if apply_imagenet_normalization:
151152
images = self.normalizer(images)
152-
B, C, H, W = images.shape
153153
logits = self.detector.forward(images)
154+
# Remove the padding, if any
155+
logits = logits[..., :H, :W]
154156
if crop_h is not None and crop_w is not None:
155157
logits = logits[..., :crop_h, :crop_w]
156158
H, W = crop_h, crop_w

0 commit comments

Comments
 (0)