Skip to content

Commit f5741dd

Browse files
committed
Handling tiny images and adding a test.
1 parent 6b829be commit f5741dd

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

test/test_transforms.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,6 +1263,17 @@ def test_adjust_sharpness(self):
12631263
y_ans = np.array(y_ans, dtype=np.uint8).reshape(x_shape)
12641264
self.assertTrue(np.allclose(y_np, y_ans))
12651265

1266+
# test 3
1267+
x_shape = [2, 2, 3]
1268+
x_data = [0, 5, 13, 54, 135, 226, 37, 8, 234, 90, 255, 1]
1269+
x_np = np.array(x_data, dtype=np.uint8).reshape(x_shape)
1270+
x_pil = Image.fromarray(x_np, mode='RGB')
1271+
x_th = torch.tensor(x_np.transpose(2, 0, 1))
1272+
y_pil = F.adjust_sharpness(x_pil, 2)
1273+
y_np = np.array(y_pil).transpose(2, 0, 1)
1274+
y_th = F.adjust_sharpness(x_th, 2)
1275+
self.assertTrue(np.allclose(y_np, y_th.numpy()))
1276+
12661277
def test_adjust_gamma(self):
12671278
x_shape = [2, 2, 3]
12681279
x_data = [0, 5, 13, 54, 135, 226, 37, 8, 234, 90, 255, 1]

torchvision/transforms/functional_tensor.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,4 +1258,7 @@ def adjust_sharpness(img: Tensor, sharpness_factor: float) -> Tensor:
12581258

12591259
_assert_channels(img, [1, 3])
12601260

1261+
if img.size(-1) <= 2 or img.size(-2) <= 2:
1262+
return img
1263+
12611264
return _blend(img, _blur_image(img), sharpness_factor)

0 commit comments

Comments
 (0)