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

Method __call__

utils/transforms.py:102–124  ·  view source on GitHub ↗
(self, img, target)

Source from the content-addressed store, hash-verified

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

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected