MCPcopy Create free account
hub / github.com/XLearning-SCU/2022-CVPR-DART / __call__

Method __call__

ChannelAug.py:115–140  ·  view source on GitHub ↗
(self, img)

Source from the content-addressed store, hash-verified

113 self.r1 = r1
114
115 def __call__(self, img):
116
117 if random.uniform(0, 1) > self.probability:
118 return img
119
120 for attempt in range(100):
121 area = img.size()[1] * img.size()[2]
122
123 target_area = random.uniform(self.sl, self.sh) * area
124 aspect_ratio = random.uniform(self.r1, 1/self.r1)
125
126 h = int(round(math.sqrt(target_area * aspect_ratio)))
127 w = int(round(math.sqrt(target_area / aspect_ratio)))
128
129 if w < img.size()[2] and h < img.size()[1]:
130 x1 = random.randint(0, img.size()[1] - h)
131 y1 = random.randint(0, img.size()[2] - w)
132 if img.size()[0] == 3:
133 img[0, x1:x1+h, y1:y1+w] = self.mean[0]
134 img[1, x1:x1+h, y1:y1+w] = self.mean[1]
135 img[2, x1:x1+h, y1:y1+w] = self.mean[2]
136 else:
137 img[0, x1:x1+h, y1:y1+w] = self.mean[0]
138 return img
139
140 return img

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected