From 08a03cc482def59d995e74989dcc7b18ac9c8835 Mon Sep 17 00:00:00 2001 From: isalia20 Date: Wed, 28 Aug 2024 01:21:28 +0400 Subject: [PATCH 1/2] smaller gpu memory usage in erosion --- kornia/morphology/morphology.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kornia/morphology/morphology.py b/kornia/morphology/morphology.py index 23431781cd3..2f227a91e2f 100644 --- a/kornia/morphology/morphology.py +++ b/kornia/morphology/morphology.py @@ -183,7 +183,7 @@ def erosion( if engine == "unfold": output = output.unfold(2, se_h, 1).unfold(3, se_w, 1) - output, _ = torch.min(output - neighborhood, 4) + output, _ = torch.min(output.sub_(neighborhood), 4) output, _ = torch.min(output, 4) elif engine == "convolution": B, C, H, W = tensor.size() From 16eb73ffa88dc87411392e3ae9992c44512eedbe Mon Sep 17 00:00:00 2001 From: isalia20 Date: Wed, 28 Aug 2024 01:59:12 +0400 Subject: [PATCH 2/2] call to contiguous --- kornia/morphology/morphology.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kornia/morphology/morphology.py b/kornia/morphology/morphology.py index 2f227a91e2f..93f75b18aa2 100644 --- a/kornia/morphology/morphology.py +++ b/kornia/morphology/morphology.py @@ -182,7 +182,7 @@ def erosion( neighborhood[kernel == 0] = -max_val if engine == "unfold": - output = output.unfold(2, se_h, 1).unfold(3, se_w, 1) + 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":