def main():
    args = get_arguments()
    os.environ["CUDA_VISIBLE_DEVICES"] = "0"
    ## FOR REPRODUCIBILITY OF RESULTS
    seed = 1777777
    utils.reproducibility(args, seed)

    utils.make_dirs(args.save)
    utils.save_arguments(args, args.save)

    training_generator, val_generator, full_volume, affine = medical_loaders.generate_datasets(
        args, path='.././datasets')
    model, optimizer = medzoo.create_model(args)
    criterion = create_loss('CrossEntropyLoss')
    criterion = DiceLoss(classes=args.classes,
                         weight=torch.tensor([0.1, 1, 1, 1]).cuda())

    if args.cuda:
        model = model.cuda()
        print("Model transferred in GPU.....")

    trainer = Trainer(args,
                      model,
                      criterion,
                      optimizer,
                      train_data_loader=training_generator,
                      valid_data_loader=val_generator,
                      lr_scheduler=None)
    print("START TRAINING...")
    trainer.training()
def train():
    # args = brats2019_arguments()

    utils.reproducibility(args, seed)
    utils.make_dirs(args.save)

    (
        training_generator,
        val_generator,
        full_volume,
        affine,
    ) = medical_loaders.generate_datasets(args)
    model, optimizer = medzoo.create_model(args)
    val_criterion = DiceLoss(classes=11, skip_index_after=args.classes)

    # criterion = DiceLoss(classes=3, skip_index_after=args.classes)
    # criterion = DiceLoss(classes=args.classes)
    criterion = torch.nn.CrossEntropyLoss()

    if args.cuda:
        model = model.cuda()
        print("Model transferred in GPU.....")

    trainer = train_module.Trainer(
        args,
        model,
        criterion,
        optimizer,
        val_criterion=val_criterion,
        train_data_loader=training_generator,
        valid_data_loader=val_generator,
        lr_scheduler=None,
    )
    print("START TRAINING...")
    trainer.training()
Example #3
0
def main():
    args = get_arguments()

    os.environ["CUDA_VISIBLE_DEVICES"] = "0"
    ## FOR REPRODUCIBILITY OF RESULTS
    seed = 1777777
    utils.reproducibility(args, seed)
    utils.make_dirs(args.save)
    name_model = args.model + "_" + args.dataset_name + "_" + utils.datestr()

    # TODO visual3D_temp.Basewriter package
    writer = SummaryWriter(log_dir='./runs/' + name_model, comment=name_model)

    training_generator, val_generator, full_volume, affine = medical_loaders.generate_datasets(
        args, path='.././datasets')
    model, optimizer = medzoo.create_model(args)

    if args.cuda:
        model = model.cuda()
        print("Model transferred in GPU.....")

    print("START TRAINING...")
    for epoch in range(1, args.nEpochs + 1):
        train(args, model, training_generator, optimizer, epoch, writer)
        val_metrics, confusion_matrix = validation(args, model, val_generator,
                                                   epoch, writer)
Example #4
0
 def ixi(self):
     self.args.inChannels = 2
     self.args.inModalities = 2
     self.args.dim = (1, 1, 1)
     self.args.dataset_name = "ixi"
     generator, affine = medical_loaders.generate_datasets(self.args, path='.././datasets')
     print("ixi  OK!", len(generator))
Example #5
0
def main():
    args = get_arguments()
    #os.environ["CUDA_VISIBLE_DEVICES"] = "0"
    ## FOR REPRODUCIBILITY OF RESULTS
    seed = 1777777
    utils.reproducibility(args, seed)

    training_generator, val_generator, full_volume, affine = medical_loaders.generate_datasets(
        args, path='./datasets')
    model, optimizer = medzoo.create_model(args)
    #
    criterion = DiceLoss(classes=args.classes)
    #
    # ## TODO LOAD PRETRAINED MODEL
    print(affine.shape)
    model.restore_checkpoint(args.pretrained)
    if args.cuda:
        model = model.cuda()
        full_volume = full_volume.cuda()
        print("Model transferred in GPU.....")
    x = torch.randn(3, 156, 240, 240).cuda()
    print(full_volume.shape)
    output = non_overlap_padding(args,
                                 full_volume,
                                 model,
                                 criterion,
                                 kernel_dim=(32, 32, 32))
Example #6
0
def main():
    args = get_arguments()

    utils.reproducibility(args, seed)
    utils.make_dirs(args.save)

    training_generator, val_generator, full_volume, affine = medical_loaders.generate_datasets(
        args, path='.././datasets')
    model, optimizer = medzoo.create_model(args)
    criterion = DiceLoss(classes=args.classes)

    if args.cuda:
        model = model.cuda()
        print("Model transferred in GPU.....")

    trainer = train.Trainer(args,
                            model,
                            criterion,
                            optimizer,
                            train_data_loader=training_generator,
                            valid_data_loader=val_generator,
                            lr_scheduler=None)
    print("START TRAINING...")
    trainer.training()

    visualize_3D_no_overlap_new(args, full_volume, affine, model, 10, args.dim)
Example #7
0
 def brats2018(self):
     self.args.inChannels = 4
     self.args.inModalities = 4
     self.args.classes = 5
     self.args.dataset_name = "brats2018"
     training_generator, val_generator, full_volume, affine = medical_loaders.generate_datasets(self.args,
                                                                                                path='.././datasets')
     print("brats2018  OK!", len(training_generator), len(val_generator))
Example #8
0
    def ISEG2017(self):
        self.args.inChannels = 2
        self.args.inModalities = 2
        self.args.dataset_name = "iseg2017"
        training_generator, val_generator, full_volume, affine = medical_loaders.generate_datasets(self.args,
                                                                                                   path='.././datasets')

        print("iseg  OK! ", len(training_generator), len(val_generator))
Example #9
0
 def miccai2019(self):
     self.args.dim = (64, 64)
     self.args.inChannels = 3
     self.args.inModalities = 1
     self.args.classes = 7
     self.args.dataset_name = "miccai2019"
     training_generator, val_generator, full_volume, affine = medical_loaders.generate_datasets(self.args,
                                                                                                path='.././datasets')
     print("miccai2019  OK!", len(training_generator), len(val_generator))
def main():
    args = get_arguments()
    utils.reproducibility(args, seed)
    utils.make_dirs(args.save)

    training_generator, val_generator, full_volume, affine = medical_loaders.generate_datasets(args,
                                                                                               path='.././datasets')
    model, optimizer = medzoo.create_model(args)
    criterion = DiceLoss(classes=args.classes)

    if args.cuda:
        model = model.cuda()

    trainer = train.Trainer(args, model, criterion, optimizer, train_data_loader=training_generator,
                            valid_data_loader=val_generator)
    trainer.training()
def main():
    args = get_arguments()
    utils.reproducibility(args, seed)
    utils.make_dirs(args.save)

    training_generator, val_generator, full_volume, affine = medical_loaders.generate_datasets(
        args, path='.././datasets')
    model, optimizer = medzoo.create_model(args)
    criterion = DiceLoss(
        classes=args.classes
    )  # ,skip_index_after=2,weight=torch.tensor([0.00001,1,1,1]).cuda())

    if args.cuda:
        model = model.cuda()
        print("Model transferred in GPU.....")

    trainer = train.Trainer(args,
                            model,
                            criterion,
                            optimizer,
                            train_data_loader=training_generator,
                            valid_data_loader=val_generator)
    print("START TRAINING...")
    trainer.training()
Example #12
0
 def MRBRAINS_9_class(self):
     self.args.classes = 9
     training_generator, val_generator, full_volume, affine = medical_loaders.generate_datasets(self.args,
                                                                                                path='.././datasets')
     print("mrbrains 8 OK!", len(training_generator), len(val_generator))