コード例 #1
0
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,

        ])
コード例 #2
0
def get_transforms_det(size_input=256, size_crop=512):
    return transforms.Compose([
        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 ),
        mtrans.ToTensor(),
        normalize,
    ])
コード例 #3
0
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,
    ])
コード例 #4
0
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!!!")
コード例 #5
0
from pytvision import visualization as view


data = SyntethicCircleDataset(
        count=100,
        generate=SyntethicCircleDataset.generate_image_mask_and_weight,
        imsize=(512,512),
        sigma=0.01,
        bdraw_grid=True,
        transform=transforms.Compose([

              ## resize and crop
                           
              mtrans.ToResize( (400,400), resize_mode='asp' ) ,
              #mtrans.CenterCrop( (200,200) ),
              mtrans.RandomCrop( (255,255), limit=50, padding_mode=cv2.BORDER_REFLECT_101  ),
              #mtrans.ToResizeUNetFoV(388, cv2.BORDER_REFLECT_101),
              
              ## color 

              #mtrans.RandomSaturation(),
              #mtrans.RandomHueSaturationShift(),
              #mtrans.RandomHueSaturation(),
              #mtrans.RandomRGBShift(),
              #mtrans.ToNegative(),
              #mtrans.RandomRGBPermutation(),
              #mtrans.ToGrayscale(),

              ## blur

              #mtrans.ToRandomTransform( mtrans.ToLinealMotionBlur( lmax=1 ), prob=0.5 ),
コード例 #6
0
pathdataset = '/home/pdmf/.datasets/'
namedataset = 'cellcaltech0001'
sub_folder = ''
folders_images = 'images'
folders_labels = 'labels'
base_folder = os.path.join(pathdataset, namedataset)

data = CTECHDataset(
    base_folder,
    sub_folder,
    count=10,
    transform=transforms.Compose([
        mtrans.ToResize((500, 500), resize_mode='crop'),
        mtrans.RandomCrop((255, 255),
                          limit=50,
                          padding_mode=cv2.BORDER_CONSTANT),
        #mtrans.ToResizeUNetFoV(388, cv2.BORDER_REFLECT_101),
        mtrans.ToTensor(),
        mtrans.ToNormalization(),
    ]))

# sample = data[0]
# for k,v in sample.items():
#     print( k, ':', v.shape, v.min(), v.max() )
# print('\n')
# #assert(False)

dataloader = DataLoader(data, batch_size=3, shuffle=False, num_workers=1)

label_batched = []