Skip to content

Commit 89edfaa

Browse files
authored
add __repr__ for transforms.RandomErasing (#3491)
1 parent 945f3a8 commit 89edfaa

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

test/test_transforms.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1991,6 +1991,9 @@ def test_random_erasing(self):
19911991
p_value = stats.binom_test(count_bigger_then_ones, trial, p=0.5)
19921992
self.assertGreater(p_value, 0.0001)
19931993

1994+
# Checking if RandomErasing can be printed as string
1995+
t.__repr__()
1996+
19941997

19951998
if __name__ == '__main__':
19961999
unittest.main()

torchvision/transforms/transforms.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,6 +1630,14 @@ def forward(self, img):
16301630
return F.erase(img, x, y, h, w, v, self.inplace)
16311631
return img
16321632

1633+
def __repr__(self):
1634+
s = '(p={}, '.format(self.p)
1635+
s += 'scale={}, '.format(self.scale)
1636+
s += 'ratio={}, '.format(self.ratio)
1637+
s += 'value={}, '.format(self.value)
1638+
s += 'inplace={})'.format(self.inplace)
1639+
return self.__class__.__name__ + s
1640+
16331641

16341642
class GaussianBlur(torch.nn.Module):
16351643
"""Blurs image with randomly chosen Gaussian blur.

0 commit comments

Comments
 (0)