MCPcopy Create free account
hub / github.com/MotrixLab/AiOS / augmentation_instance_sample

Function augmentation_instance_sample

util/preprocessing.py:200–259  ·  view source on GitHub ↗
(img, bbox, data_split,data,dataname)

Source from the content-addressed store, hash-verified

198 return img, trans, inv_trans, rot, do_flip
199
200def augmentation_instance_sample(img, bbox, data_split,data,dataname):
201 ori_shape = img.shape[:2][::-1]
202
203 if getattr(cfg, 'no_aug', False) and data_split == 'train':
204 scale, rot, color_scale, do_flip,size,crop,sample_ratio,sample_prob = 1.0, 0.0, np.array([1, 1, 1]), False, ori_shape, np.array([1,1]), 0,0
205
206 size = random.choice(cfg.train_sizes)
207 max_size = cfg.train_max_size
208 elif data_split == 'train':
209 scale, rot, color_scale, do_flip, crop, sample_ratio,sample_prob = get_aug_config(dataname)
210 rot=0
211 # scale, rot, do_flip, crop = 1.0, 0.0, False, np.array([1,1])
212 size = random.choice(cfg.train_sizes)
213 max_size = cfg.train_max_size
214 else:
215 scale, rot, color_scale, do_flip, crop,sample_ratio,sample_prob = 1.0, 0.0, np.array([1, 1, 1]), False, np.array([1,1]),0,0
216 size = random.choice(cfg.test_sizes)
217 max_size = cfg.test_max_size
218
219
220 if random.random() < sample_prob:
221 crop_person_number = len(data['bbox'])
222
223 if random.random() < sample_ratio:
224 if random.random() < 0.6:
225 crop_person_number_sample = 1
226 else:
227 crop_person_number_sample = np.random.randint(crop_person_number) + 1
228 else:
229 crop_person_number_sample = crop_person_number
230 sample_ids = np.array(
231 random.sample(list(range(crop_person_number)), crop_person_number_sample))
232
233 bbox_xyxy = []
234
235 bbox_xyxy = np.stack(data['bbox'],axis=0)[sample_ids]
236
237 leftTop_ = bbox_xyxy[:, :2]
238 leftTop_ = np.array([np.min(leftTop_[:, 0]), np.min(leftTop_[:, 1])])
239 rightBottom_ = bbox_xyxy[:, 2:4]
240 rightBottom_ = np.array(
241 [np.max(rightBottom_[:, 0]),
242 np.max(rightBottom_[:, 1])])
243 crop_bbox_xyxy = np.concatenate([leftTop_, rightBottom_])
244 crop_bbox_xywh = crop_bbox_xyxy.copy()
245 crop_bbox_xywh[2:] = crop_bbox_xywh[2:]-crop_bbox_xywh[:2]
246 crop_bbox_xywh = adjust_bounding_box(crop_bbox_xywh,ori_shape[0],ori_shape[1])
247 else:
248 crop_bbox_xywh = bbox.copy()
249 reshape_size = resize(crop_bbox_xywh[2:], size, max_size)
250 # try:
251 # reshape_size = resize(crop_bbox_xywh[2:], size, max_size)
252 # except Exception as e:
253 # print(crop_bbox_xywh)
254 # print(size)
255 # print(max_size)
256 # raise e
257 img, trans, inv_trans = generate_patch_image(img, crop_bbox_xywh, 1, rot, do_flip, reshape_size[::-1])

Callers 3

__getitem__Method · 0.90
__getitem__Method · 0.90
__getitem__Method · 0.90

Calls 9

get_aug_configFunction · 0.85
adjust_bounding_boxFunction · 0.85
generate_patch_imageFunction · 0.85
maxMethod · 0.80
concatenateMethod · 0.80
copyMethod · 0.80
resizeFunction · 0.70
randomMethod · 0.45
sampleMethod · 0.45

Tested by

no test coverage detected