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

Function augmentation_keep_size

util/preprocessing.py:173–198  ·  view source on GitHub ↗
(img, bbox, data_split)

Source from the content-addressed store, hash-verified

171 return scale, rot, color_scale, do_flip, crop_hw, sample_ratio, sample_prob
172
173def augmentation_keep_size(img, bbox, data_split):
174 ori_shape = img.shape[:2][::-1]
175 if getattr(cfg, 'no_aug', False) and data_split == 'train':
176 scale, rot, color_scale, do_flip,size,crop = 1.0, 0.0, np.array([1, 1, 1]), False, ori_shape, np.array([1,1])
177
178 size = random.choice(cfg.train_sizes)
179 max_size = cfg.train_max_size
180 elif data_split == 'train':
181 scale, rot, color_scale, do_flip, crop = get_aug_config()
182 rot=0
183 # scale, rot, do_flip, crop = 1.0, 0.0, False, np.array([1,1])
184 size = random.choice(cfg.train_sizes)
185 max_size = cfg.train_max_size
186 else:
187 scale, rot, color_scale, do_flip, crop = 1.0, 0.0, np.array([1, 1, 1]), False, np.array([1,1])
188 size = random.choice(cfg.test_sizes)
189 max_size = cfg.test_max_size
190
191 crop_bbox_wh = (bbox[2:]*crop).astype(np.uint32)
192 xy_range = img.shape[:2][::-1]-crop_bbox_wh
193 crop_bbox_xywh = np.array([np.random.randint(0,xy_range[0]+1),np.random.randint(0,xy_range[1]+1),crop_bbox_wh[0],crop_bbox_wh[1]])
194 reshape_size = resize(crop_bbox_xywh[2:], size, max_size)
195
196 img, trans, inv_trans = generate_patch_image(img, crop_bbox_xywh, 1, rot, do_flip, reshape_size[::-1])
197 img = np.clip(img * color_scale[None, None, :], 0, 255)
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]

Callers 4

__getitem__Method · 0.90
__getitem__Method · 0.90
__getitem__Method · 0.90
__getitem__Method · 0.90

Calls 3

get_aug_configFunction · 0.85
generate_patch_imageFunction · 0.85
resizeFunction · 0.70

Tested by

no test coverage detected