diff --git a/kornia/morphology/morphology.py b/kornia/morphology/morphology.py index 23431781cd3..93f75b18aa2 100644 --- a/kornia/morphology/morphology.py +++ b/kornia/morphology/morphology.py @@ -182,8 +182,8 @@ def erosion( neighborhood[kernel == 0] = -max_val if engine == "unfold": - output = output.unfold(2, se_h, 1).unfold(3, se_w, 1) - output, _ = torch.min(output - neighborhood, 4) + output = output.unfold(2, se_h, 1).unfold(3, se_w, 1).contiguous() + output, _ = torch.min(output.sub_(neighborhood), 4) output, _ = torch.min(output, 4) elif engine == "convolution": B, C, H, W = tensor.size()