def get_train_transform(image_size, augmentation=None): if augmentation is None: augmentation = 'none' LEVELS = { 'none': get_none_augmentations, 'light': get_light_augmentations, 'medium': get_medium_augmentations, 'hard': get_hard_augmentations, 'hard2': get_hard_augmentations_v2 } assert augmentation in LEVELS.keys() augmentation = LEVELS[augmentation](image_size) longest_size = max(image_size[0], image_size[1]) return A.Compose([ Resize(int(config.img_height * 1.5), int(config.img_weight * 1.5)), CenterCrop(config.img_height, config.img_weight), A.LongestMaxSize(longest_size, interpolation=cv2.INTER_CUBIC), A.PadIfNeeded(image_size[0], image_size[1], border_mode=cv2.BORDER_CONSTANT, value=0), augmentation, A.Normalize(), ToTensor() ])
def get_test_transform(image_size): longest_size = max(image_size[0], image_size[1]) return A.Compose([ #Resize(int(config.img_height*1.5),int(config.img_weight*1.5)), CenterCrop(config.img_height, config.img_weight), A.LongestMaxSize(longest_size, interpolation=cv2.INTER_CUBIC), A.PadIfNeeded(image_size[0], image_size[1], border_mode=cv2.BORDER_CONSTANT, value=0), A.Normalize(), ToTensor() ])
def __init__(self, df, df_controls, stats_experiments, img_dir, mode, verbose=True, channels=[1, 2, 3, 4, 5, 6]): self.records = deepcopy(df).to_records(index=False) df_conts = deepcopy(df_controls) mask = (df_conts['well_type'] == 'negative_control') & \ (df_conts['well'] == 'B02') df_neg_conts = df_conts[mask] self.records_neg_conts = df_neg_conts.to_records(index=False) mask = (df_conts['well_type'] == 'positive_control') df_pos_conts = df_conts[mask] self.records_pos_conts = df_pos_conts.to_records(index=False) self.stats_exps = stats_experiments self.mode = mode self.channels = channels self.img_dir = img_dir self.len = df.shape[0] self.transform_train = Compose([ VerticalFlip(p=0.5), HorizontalFlip(p=0.5), ShiftScaleRotate( shift_limit=0, scale_limit=0, rotate_limit=180, p=1.0), RandomCrop(height=364, width=364, p=1.0) ], p=1.0) self.transform_val = Compose( [CenterCrop(height=364, width=364, p=1.0)], p=1.0) if verbose: print() self.imgs = self._load_imgs(self.records, desc='Images', verbose=verbose) self.imgs_neg_conts = self._load_imgs(self.records_neg_conts, desc='Negative controls', verbose=verbose) self.imgs_pos_conts = self._load_imgs(self.records_pos_conts, desc='Positive controls', verbose=verbose)