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

Class cutout_patch

utils/mask.py:221–243  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

219
220
221class cutout_patch:
222 def __init__(self, mask_size=2):
223 self.mask_size = mask_size
224
225 def __call__(self, features):
226 if random.random() < 0.5:
227 y1_max = features.shape[3] - self.mask_size
228 num_masks = 1
229 for i in range(num_masks):
230 mask_y1 = torch.randint(y1_max, (features.shape[0],))
231 mask_y2 = mask_y1 + self.mask_size
232 for k in range(features.shape[0]):
233 features[k, :, :, mask_y1[k] : mask_y2[k]] = 0
234 else:
235 x1_max = features.shape[3] - self.mask_size
236 num_masks = 1
237 for i in range(num_masks):
238 mask_x1 = torch.randint(x1_max, (features.shape[0],))
239 mask_x2 = mask_x1 + self.mask_size
240 for k in range(features.shape[0]):
241 features[k, :, mask_x1[k] : mask_x2[k], :] = 0
242
243 return features
244
245
246class erase_patch:

Callers 1

forwardMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected