MCPcopy Create free account
hub / github.com/AtlasAnalyticsLab/AdaFisher / __call__

Method __call__

Image_Classification/src/utils/data.py:26–54  ·  view source on GitHub ↗

Args: img (Tensor): Tensor image of size (C, H, W). Returns: Tensor: Image with n_holes of dimension length x length cut out of it.

(self, img)

Source from the content-addressed store, hash-verified

24 self.length = length
25
26 def __call__(self, img):
27 """
28 Args:
29 img (Tensor): Tensor image of size (C, H, W).
30 Returns:
31 Tensor: Image with n_holes of dimension length x length cut out of
32 it.
33 """
34 h = img.size(1)
35 w = img.size(2)
36
37 mask = np.ones((h, w), np.float32)
38
39 for n in range(self.n_holes):
40 y = np.random.randint(h)
41 x = np.random.randint(w)
42
43 y1 = np.clip(y - self.length // 2, 0, h)
44 y2 = np.clip(y + self.length // 2, 0, h)
45 x1 = np.clip(x - self.length // 2, 0, w)
46 x2 = np.clip(x + self.length // 2, 0, w)
47
48 mask[y1: y2, x1: x2] = 0.
49
50 mask = torch.from_numpy(mask)
51 mask = mask.expand_as(img)
52 img = img * mask
53
54 return img
55
56
57def get_data(

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected