MCPcopy Create free account
hub / github.com/OpenGVLab/HumanBench / __call__

Method __call__

PATH/core/augmentation.py:147–248  ·  view source on GitHub ↗
(self, img)

Source from the content-addressed store, hash-verified

145 self.hat_ratio = hat_ratio
146
147 def __call__(self, img):
148 ## transform
149 scale_diff_h = (np.random.rand()*2-1)*self.scale_aug
150 scale_diff_w = (np.random.rand()*2-1)*self.scale_aug
151 crop_aug_h = self.crop_size*(1+scale_diff_h)
152 crop_aug_w = self.crop_size*(1+scale_diff_w)
153
154 trans_diff_h = (np.random.rand()*2-1)*self.trans_aug
155 trans_diff_w = (np.random.rand()*2-1)*self.trans_aug
156
157 h, w, _ = img.shape
158 ct_x = w/2*(1+trans_diff_w)
159 ct_y = (h/2+self.crop_center_y_offset)*(1+trans_diff_h)
160
161 if ct_x < crop_aug_w/2:
162 crop_aug_w = ct_x*2 - 0.5
163 if ct_y < crop_aug_h/2:
164 crop_aug_h = ct_y*2 - 0.5
165 if ct_x + crop_aug_w/2 >= w:
166 crop_aug_w = (w-ct_x)*2 - 0.5
167 if ct_y + crop_aug_h/2 >= h:
168 crop_aug_h = (h-ct_y)*2 - 0.5
169
170 #rect = (ct_x-crop_aug_w/2, ct_y-crop_aug_h/2, ct_x+crop_aug_w/2, ct_y+crop_aug_h/2)
171 #img = img.resize((self.final_size, self.final_size), box=rect)
172 t = int(np.ceil(ct_y-crop_aug_h/2))
173 #d = int(np.ceil(ct_y+crop_aug_h/2))
174 l = int(np.ceil(ct_x-crop_aug_w/2))
175 #r = int(np.ceil(ct_x+crop_aug_w/2))
176 img = img[t:int(t+crop_aug_h),l:int(l+crop_aug_w),:]
177 img = cv2.resize(img, (self.final_size, self.final_size))
178
179 #print(self.flip)
180 if np.random.rand() <= self.flip:
181 #print('do flip')
182 img = cv2.flip(img, 1)
183
184 ## to BGR
185 #img = np.array(img)
186 #img = img[:,:,[2,1,0]]
187 if self.mask_spec == True:
188 LEx = 70.7
189 LEy = 113.0
190 REx = 108.23
191 REy = 113.0
192 Mx = 89.43
193 My = 153.51
194 LEx_mod = (LEx - (ct_x - crop_aug_w/2))*(self.final_size/crop_aug_w)
195 LEy_mod = (LEy - (ct_y - crop_aug_h/2))*(self.final_size/crop_aug_h)
196 REx_mod = (REx - (ct_x - crop_aug_w/2))*(self.final_size/crop_aug_w)
197 REy_mod = (REy - (ct_y - crop_aug_h/2))*(self.final_size/crop_aug_h)
198 Mx_mod = (Mx - (ct_x - crop_aug_w/2))*(self.final_size/crop_aug_w)
199 My_mod = (My - (ct_y - crop_aug_h/2))*(self.final_size/crop_aug_h)
200
201 print_flag = False
202 totaltemprand = np.random.rand()
203 if totaltemprand < self.total_ratio:
204 temprand = np.random.rand()

Callers

nothing calls this directly

Calls 1

resizeMethod · 0.80

Tested by

no test coverage detected