MCPcopy Create free account
hub / github.com/Kitware/COAT / RandomErasing

Class RandomErasing

utils/transforms.py:94–124  ·  view source on GitHub ↗

https://github.com/zhunzhong07/CamStyle/blob/master/reid/utils/data/transforms.py

Source from the content-addressed store, hash-verified

92
93
94class RandomErasing(object):
95 '''
96 https://github.com/zhunzhong07/CamStyle/blob/master/reid/utils/data/transforms.py
97 '''
98 def __init__(self, EPSILON=0.5, mean=[0.485, 0.456, 0.406]):
99 self.EPSILON = EPSILON
100 self.mean = mean
101
102 def __call__(self, img, target):
103 if random.uniform(0, 1) > self.EPSILON:
104 return img, target
105
106 for attempt in range(100):
107 area = img.size()[1] * img.size()[2]
108
109 target_area = random.uniform(0.02, 0.2) * area
110 aspect_ratio = random.uniform(0.3, 3)
111
112 h = int(round(math.sqrt(target_area * aspect_ratio)))
113 w = int(round(math.sqrt(target_area / aspect_ratio)))
114
115 if w <= img.size()[2] and h <= img.size()[1]:
116 x1 = random.randint(0, img.size()[1] - h)
117 y1 = random.randint(0, img.size()[2] - w)
118 img[0, x1:x1 + h, y1:y1 + w] = self.mean[0]
119 img[1, x1:x1 + h, y1:y1 + w] = self.mean[1]
120 img[2, x1:x1 + h, y1:y1 + w] = self.mean[2]
121
122 return img, target
123
124 return img, target
125
126
127class ToTensor:

Callers 1

build_transformsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected