MCPcopy Create free account
hub / github.com/geekcomputers/Python / __call__

Method __call__

ML/src/python/neuralforge/data/augmentation.py:156–177  ·  view source on GitHub ↗
(self, img)

Source from the content-addressed store, hash-verified

154 self.ratio = ratio
155
156 def __call__(self, img):
157 h, w = img.shape[-2:]
158
159 d = np.random.randint(self.d1, self.d2)
160 l = int(d * self.ratio + 0.5)
161
162 mask = np.ones((h, w), np.float32)
163 st_h = np.random.randint(d)
164 st_w = np.random.randint(d)
165
166 for i in range(h // d + 1):
167 s_h = d * i + st_h
168 t_h = min(s_h + l, h)
169 for j in range(w // d + 1):
170 s_w = d * j + st_w
171 t_w = min(s_w + l, w)
172 mask[s_h:t_h, s_w:t_w] = 0
173
174 mask = torch.from_numpy(mask).to(img.device)
175 img = img * mask
176
177 return img
178
179class RandomErasing:
180 def __init__(self, probability: float = 0.5, sl: float = 0.02, sh: float = 0.4, r1: float = 0.3):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected