def get_transforms_aug( size_input ): return transforms.Compose([ #------------------------------------------------------------------ #Resize mtrans.ToResize( (size_input,size_input), resize_mode='square', padding_mode=cv2.BORDER_REPLICATE), #------------------------------------------------------------------ #Colors mtrans.ToRandomTransform( mtrans.RandomBrightness( factor=0.25 ), prob=0.750 ), mtrans.ToRandomTransform( mtrans.RandomContrast( factor=0.25 ), prob=0.750 ), mtrans.ToRandomTransform( mtrans.RandomGamma( factor=0.25 ), prob=0.750 ), # mtrans.ToRandomTransform( mtrans.RandomRGBPermutation(), prob=0.50 ), # mtrans.ToRandomTransform( mtrans.CLAHE(), prob=0.25 ), mtrans.ToRandomTransform(mtrans.ToGaussianBlur( sigma=0.05 ), prob=0.25 ), # mtrans.ToRandomTransform(mtrans.ToGaussianNoise( sigma=0.05 ), prob=0.25 ), # mtrans.ToRandomTransform( mtrans.RandomBrightness( factor=0.25 ), prob=0.50 ), # mtrans.ToRandomTransform( mtrans.RandomContrast( factor=0.25 ), prob=0.50 ), # mtrans.ToRandomTransform( mtrans.RandomGamma( factor=0.25 ), prob=0.50 ), # mtrans.ToRandomTransform( mtrans.RandomRGBPermutation(), prob=0.50 ), # mtrans.ToRandomTransform( mtrans.CLAHE(), prob=0.25 ), # mtrans.ToRandomTransform( mtrans.ToGaussianBlur( sigma=0.05 ), prob=0.25 ), #------------------------------------------------------------------ mtrans.ToTensor(), normalize, ])
def get_transforms_fer_aug( size_input ): return transforms.Compose([ #------------------------------------------------------------------ #Resize input mtrans.ToResize( (48, 48), resize_mode='square', padding_mode=cv2.BORDER_REFLECT ), #------------------------------------------------------------------ #Geometric mtrans.RandomScale(factor=0.2, padding_mode=cv2.BORDER_REPLICATE ), mtrans.ToRandomTransform( mtrans.RandomGeometricalTransform( angle=30, translation=0.2, warp=0.02, padding_mode=cv2.BORDER_REFLECT ), prob=0.5 ), mtrans.ToRandomTransform( mtrans.VFlip(), prob=0.5 ), #mtrans.ToRandomTransform( mtrans.HFlip(), prob=0.5 ), #------------------------------------------------------------------ #Colors mtrans.ToRandomTransform( mtrans.RandomBrightness( factor=0.25 ), prob=0.50 ), mtrans.ToRandomTransform( mtrans.RandomContrast( factor=0.25 ), prob=0.50 ), mtrans.ToRandomTransform( mtrans.RandomGamma( factor=0.25 ), prob=0.50 ), mtrans.ToRandomTransform( mtrans.RandomRGBPermutation(), prob=0.50 ), mtrans.ToRandomTransform( mtrans.CLAHE(), prob=0.25 ), mtrans.ToRandomTransform( mtrans.ToGaussianBlur( sigma=0.05 ), prob=0.25 ), #------------------------------------------------------------------ #Resize mtrans.ToResize( (size_input+5, size_input+5), resize_mode='square', padding_mode=cv2.BORDER_REFLECT ), mtrans.RandomCrop( (size_input, size_input), limit=2, padding_mode=cv2.BORDER_REFLECT ), #------------------------------------------------------------------ mtrans.ToGrayscale(), mtrans.ToTensor(), normalize, ])
def get_transforms_geom_color(): #7 return transforms.Compose([ #------------------------------------------------------------------ #Resize # #mtrans.CenterCrop((1008, 1008)), #mtrans.RandomCrop( (size_crop, size_crop), limit=10, padding_mode=cv2.BORDER_REFLECT_101 ), #mtrans.ToResize( (size_input, size_input), resize_mode='square', padding_mode=cv2.BORDER_REFLECT_101 ), #mtrans.ToPad( pad, pad, padding_mode=cv2.BORDER_CONSTANT ), #------------------------------------------------------------------ #Geometric mtrans.ToRandomTransform(mtrans.VFlip(), prob=0.5), mtrans.ToRandomTransform(mtrans.HFlip(), prob=0.5), mtrans.RandomScale(factor=0.3, padding_mode=cv2.BORDER_REFLECT_101), mtrans.ToRandomTransform(mtrans.RandomGeometricalTransform( angle=45, translation=0.2, warp=0.02, padding_mode=cv2.BORDER_REFLECT_101), prob=0.5), mtrans.ToRandomTransform(mtrans.RandomElasticDistort( size_grid=32, deform=None, padding_mode=cv2.BORDER_REFLECT_101), prob=0.5), mtrans.ToRandomTransform(mtrans.RandomErased(p_grid=0.2, p_img=0.5), prob=0.1), mtrans.ToRandomTransform(mtrans.RandomLines(n_lines=5), prob=0.1), #mtrans.ToResizeUNetFoV(imsize, cv2.BORDER_REFLECT_101), #------------------------------------------------------------------ #Colors mtrans.ToRandomTransform(mtrans.RandomBrightness(factor=0.25), prob=0.50), mtrans.ToRandomTransform(mtrans.RandomContrast(factor=0.25), prob=0.50), mtrans.ToRandomTransform(mtrans.RandomGamma(factor=0.25), prob=0.50), #mtrans.ToRandomTransform( mtrans.RandomRGBPermutation(), prob=0.50 ), #mtrans.ToRandomTransform( mtrans.CLAHE(), prob=0.25 ), mtrans.ToRandomTransform(mtrans.ToGaussianBlur(sigma=0.05), prob=0.1), #------------------------------------------------------------------ mtrans.ToTensor(), normalize, ])
def get_transforms_aug(size_input=256, size_crop=512): return transforms.Compose([ #------------------------------------------------------------------ #Resize # mtrans.RandomCrop((size_crop, size_crop), limit=10, padding_mode=cv2.BORDER_REFLECT_101), mtrans.ToResize((size_input, size_input), resize_mode='square', padding_mode=cv2.BORDER_REFLECT_101), #mtrans.ToPad( 5 , 5, padding_mode=cv2.BORDER_REFLECT_101 ), #------------------------------------------------------------------ #Geometric mtrans.ToRandomTransform(mtrans.VFlip(), prob=0.5), mtrans.ToRandomTransform(mtrans.HFlip(), prob=0.5), mtrans.RandomScale(factor=0.3, padding_mode=cv2.BORDER_REFLECT_101), mtrans.ToRandomTransform(mtrans.RandomGeometricalTransform( angle=45, translation=0.2, warp=0.02, padding_mode=cv2.BORDER_REFLECT_101), prob=0.5), mtrans.ToRandomTransform(mtrans.RandomElasticDistort( size_grid=32, deform=12, padding_mode=cv2.BORDER_REFLECT_101), prob=0.5), #mtrans.ToResizeUNetFoV(imsize, cv2.BORDER_REFLECT_101), #------------------------------------------------------------------ #Colors mtrans.ToRandomTransform(mtrans.RandomBrightness(factor=0.25), prob=0.50), mtrans.ToRandomTransform(mtrans.RandomContrast(factor=0.25), prob=0.50), mtrans.ToRandomTransform(mtrans.RandomGamma(factor=0.25), prob=0.50), #mtrans.ToRandomTransform( mtrans.RandomRGBPermutation(), prob=0.50 ), #mtrans.ToRandomTransform( mtrans.CLAHE(), prob=0.25 ), #mtrans.ToRandomTransform(mtrans.ToGaussianBlur( sigma=0.05 ), prob=0.25 ), #------------------------------------------------------------------ mtrans.ToTensor(), normalize, ])
def get_transforms_aug(size_input): return transforms.Compose([ #------------------------------------------------------------------ #Resize mtrans.ToResize((size_input, size_input), resize_mode='square', padding_mode=cv2.BORDER_REFLECT_101), #mtrans.ToResize( (size_input+10, size_input+10), resize_mode='square', padding_mode=cv2.BORDER_REFLECT_101 ) , #mtrans.RandomCrop( (size_input, size_input), limit=2, padding_mode=cv2.BORDER_REFLECT_101 ) , #------------------------------------------------------------------ #Geometric mtrans.RandomScale(factor=0.2, padding_mode=cv2.BORDER_REFLECT_101), mtrans.ToRandomTransform(mtrans.RandomGeometricalTransform( angle=45, translation=0.2, warp=0.02, padding_mode=cv2.BORDER_REFLECT_101), prob=0.5), mtrans.ToRandomTransform(mtrans.VFlip(), prob=0.5), mtrans.ToRandomTransform(mtrans.HFlip(), prob=0.5), #mtrans.ToRandomTransform( mtrans.RandomElasticDistort( size_grid=32, deform=12, padding_mode=cv2.BORDER_REFLECT_101 ), prob=0.5 ), #------------------------------------------------------------------ #Colors mtrans.ToRandomTransform(mtrans.RandomBrightness(factor=0.25), prob=0.50), mtrans.ToRandomTransform(mtrans.RandomContrast(factor=0.25), prob=0.50), mtrans.ToRandomTransform(mtrans.RandomGamma(factor=0.25), prob=0.50), #mtrans.ToRandomTransform( mtrans.RandomHueSaturation( hue_shift_limit=(-5, 5), sat_shift_limit=(-11, 11), val_shift_limit=(-11, 11) ), prob=0.30 ), #mtrans.ToRandomTransform( mtrans.RandomRGBPermutation(), prob=0.50 ), #mtrans.ToRandomTransform( mtrans.CLAHE(), prob=0.25 ), #mtrans.ToRandomTransform(mtrans.ToGaussianBlur( sigma=0.05 ), prob=0.25 ), #------------------------------------------------------------------ mtrans.ToTensor(), normalize, ])
def get_transforms_aug( size_input ): transforms_aug = transforms.Compose([ mtrans.ToResize( (size_input, size_input), resize_mode='square', padding_mode=cv2.BORDER_REPLICATE ) , #mtrans.ToResize( (size_input+20, size_input+20), resize_mode='asp' ) , #mtrans.RandomCrop( (size_input, size_input), limit=10, padding_mode=cv2.BORDER_REFLECT_101 ) , #------------------------------------------------------------------ #Geometric mtrans.RandomScale(factor=0.2, padding_mode=cv2.BORDER_REPLICATE ), mtrans.RandomGeometricalTransform( angle=30, translation=0.2, warp=0.02, padding_mode=cv2.BORDER_REPLICATE), mtrans.ToRandomTransform( mtrans.HFlip(), prob=0.5 ), #------------------------------------------------------------------ #Colors mtrans.ToRandomTransform( mtrans.RandomRGBPermutation(), prob=0.30 ), mtrans.ToRandomTransform( mtrans.RandomBrightness( factor=0.15 ), prob=0.50 ), mtrans.ToRandomTransform( mtrans.RandomContrast( factor=0.15 ), prob=0.50 ), mtrans.ToRandomTransform( mtrans.RandomGamma( factor=0.15 ), prob=0.50 ), mtrans.ToRandomTransform( mtrans.RandomHueSaturation( hue_shift_limit=(-5, 5), sat_shift_limit=(-11, 11), val_shift_limit=(-11, 11) ), prob=0.30 ), mtrans.ToRandomTransform( mtrans.ToGrayscale(), prob=0.30 ), #mtrans.ToRandomChoiceTransform( [ # mtrans.RandomBrightness( factor=0.15 ), # mtrans.RandomContrast( factor=0.15 ), # #mtrans.RandomSaturation( factor=0.15 ), # mtrans.RandomHueSaturation( hue_shift_limit=(-5, 5), sat_shift_limit=(-11, 11), val_shift_limit=(-11, 11) ), # mtrans.RandomGamma( factor=0.30 ), # mtrans.ToRandomTransform(mtrans.ToGrayscale(), prob=0.15 ), # ]), mtrans.ToRandomTransform(mtrans.ToGaussianBlur( sigma=0.0001), prob=0.25 ), #------------------------------------------------------------------ mtrans.ToTensor(), normalize, ]) return transforms_aug
def main(): # parameters parser = arg_parser() args = parser.parse_args() imsize = args.image_size parallel = args.parallel num_classes = 2 num_channels = 3 view_freq = 2 network = SegmentationNeuralNet( patchproject=args.project, nameproject=args.name, no_cuda=args.no_cuda, parallel=parallel, seed=args.seed, print_freq=args.print_freq, gpu=args.gpu, view_freq=view_freq, ) network.create(arch=args.arch, num_output_channels=num_classes, num_input_channels=num_channels, loss=args.loss, lr=args.lr, momentum=args.momentum, optimizer=args.opt, lrsch=args.scheduler, pretrained=args.finetuning, size_input=imsize) # resume network.resume(os.path.join(network.pathmodels, args.resume)) cudnn.benchmark = True # datasets # training dataset train_data = tgsdata.TGSDataset( args.data, tgsdata.train, count=16000, num_channels=num_channels, transform=transforms.Compose([ mtrans.ToRandomTransform(mtrans.HFlip(), prob=0.5), mtrans.ToRandomTransform(mtrans.VFlip(), prob=0.5), mtrans.ToResize((300, 300), resize_mode='squash', padding_mode=cv2.BORDER_REFLECT_101), mtrans.RandomCrop((256, 256), limit=10, padding_mode=cv2.BORDER_REFLECT_101), mtrans.RandomScale(factor=0.2, padding_mode=cv2.BORDER_REFLECT_101), mtrans.RandomGeometricalTransform( angle=30, translation=0.2, warp=0.02, padding_mode=cv2.BORDER_REFLECT_101), #mtrans.ToResizeUNetFoV(imsize, cv2.BORDER_REFLECT_101), mtrans.ToRandomTransform(mtrans.RandomBrightness(factor=0.15), prob=0.50), mtrans.ToRandomTransform(mtrans.RandomContrast(factor=0.15), prob=0.50), mtrans.ToRandomTransform(mtrans.RandomGamma(factor=0.15), prob=0.50), mtrans.ToRandomTransform(mtrans.ToGaussianBlur(), prob=0.15), mtrans.ToTensor(), mtrans.ToMeanNormalization( mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225], ) #mtrans.ToNormalization(), ])) train_loader = DataLoader(train_data, batch_size=args.batch_size, shuffle=True, num_workers=args.workers, pin_memory=network.cuda, drop_last=True) # validate dataset val_data = tgsdata.TGSDataset( args.data, tgsdata.test, count=4000, num_channels=num_channels, transform=transforms.Compose([ mtrans.ToResize((256, 256), resize_mode='squash'), #mtrans.RandomCrop( (255,255), limit=50, padding_mode=cv2.BORDER_CONSTANT ), #mtrans.ToResizeUNetFoV(imsize, cv2.BORDER_REFLECT_101), mtrans.ToTensor(), mtrans.ToMeanNormalization( mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225], ) #mtrans.ToNormalization(), ])) val_loader = DataLoader(val_data, batch_size=args.batch_size, shuffle=False, num_workers=args.workers, pin_memory=network.cuda, drop_last=True) # print neural net class print('SEG-Torch: {}'.format(datetime.datetime.now())) print(network) # training neural net network.fit(train_loader, val_loader, args.epochs, args.snapshot) print("Optimization Finished!") print("DONE!!!")