def get_arguments(): parser = argparse.ArgumentParser() parser.add_argument('--batchSz', type=int, default=4) parser.add_argument('--dataset_name', type=str, default="iseg2017") parser.add_argument('--dim', nargs="+", type=int, default=(32,32,32)) parser.add_argument('--nEpochs', type=int, default=250) parser.add_argument('--classes', type=int, default=4) parser.add_argument('--samples_train', type=int, default=1) parser.add_argument('--samples_val', type=int, default=1) parser.add_argument('--split', type=float, default=0.8) parser.add_argument('--inChannels', type=int, default=2) parser.add_argument('--inModalities', type=int, default=2) parser.add_argument('--fold_id', default='1', type=str, help='Select subject for fold validation') parser.add_argument('--lr', default=1e-2, type=float, help='learning rate (default: 1e-3)') parser.add_argument('--cuda', action='store_true', default=True) parser.add_argument('--resume', default='', type=str, metavar='PATH', help='path to latest checkpoint (default: none)') parser.add_argument('--model', type=str, default='UNET3D', choices=('VNET', 'VNET2', 'UNET3D', 'DENSENET1', 'DENSENET2', 'DENSENET3', 'HYPERDENSENET')) parser.add_argument('--opt', type=str, default='sgd', choices=('sgd', 'adam', 'rmsprop')) parser.add_argument('--pretrained', default='../saved_models/UNET3D_checkpoints/UNET3D_24_04___14_27_iseg2017_/UNET3D_24_04___14_27_iseg2017__last_epoch.pth', type=str, metavar='PATH', help='path to pretrained model') args = parser.parse_args() args.save = '../inference_checkpoints/' + args.model + '_checkpoints/' + args.model + '_{}_{}_'.format( utils.datestr(), args.dataset_name) args.tb_log_dir = '../runs/' return args
def get_arguments(): parser = argparse.ArgumentParser() parser.add_argument('--batchSz', type=int, default=2) parser.add_argument('--dataset_name', type=str, default="brats2019") parser.add_argument('--dim', nargs="+", type=int, default=(64, 64, 64)) parser.add_argument('--nEpochs', type=int, default=100) parser.add_argument('--classes', type=int, default=5) parser.add_argument('--samples_train', type=int, default=100) parser.add_argument('--samples_val', type=int, default=100) parser.add_argument('--inChannels', type=int, default=4) parser.add_argument('--inModalities', type=int, default=4) parser.add_argument('--split', default=0.8, type=float, help='Select percentage of training data(default: 0.8)') parser.add_argument('--lr', default=1e-3, type=float, help='learning rate (default: 1e-3)') parser.add_argument('--cuda', action='store_true', default=True) parser.add_argument('--resume', default='', type=str, metavar='PATH', help='path to latest checkpoint (default: none)') parser.add_argument('--model', type=str, default='UNET3D', choices=('VNET', 'VNET2', 'UNET3D', 'DENSENET1', 'DENSENET2', 'DENSENET3', 'HYPERDENSENET')) parser.add_argument('--opt', type=str, default='sgd', choices=('sgd', 'adam', 'rmsprop')) parser.add_argument('--log_dir', type=str, default='../runs/') args = parser.parse_args() args.save = '../saved_models/' + args.model + '_checkpoints/' + args.model + '_{}_{}_'.format( utils.datestr(), args.dataset_name) return args
def main(): args = get_arguments() 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) criterion = DiceLoss(classes=11, skip_index_after=args.classes) if args.cuda: torch.cuda.manual_seed(seed) model = model.cuda() print("Model transferred in GPU.....") print("START TRAINING...") for epoch in range(1, args.nEpochs + 1): train_stats = train.train_dice(args, epoch, model, training_generator, optimizer, criterion) val_stats = train.test_dice(args, epoch, model, val_generator, criterion) #old utils.write_train_val_score(writer, epoch, train_stats, val_stats) model.save_checkpoint(args.save, epoch, val_stats[0], optimizer=optimizer)
def get_arguments(): parser = argparse.ArgumentParser() parser.add_argument('--batchSz', type=int, default=4) parser.add_argument('--dataset_name', type=str, default="miccai2019") parser.add_argument('--nEpochs', type=int, default=100) parser.add_argument('--dim', nargs="+", type=int, default=(256, 256)) parser.add_argument('--classes', type=int, default=7) parser.add_argument('--inChannels', type=int, default=3) parser.add_argument('--inModalities', type=int, default=1) parser.add_argument('--samples_train', type=int, default=100) parser.add_argument('--samples_val', type=int, default=10) parser.add_argument('--fold_id', default='1', type=str, help='Select subject for fold validation') parser.add_argument('--lr', default=1e-3, type=float, help='learning rate (default: 1e-3)') parser.add_argument('--cuda', action='store_true', default=True) parser.add_argument('--resume', default='', type=str, metavar='PATH', help='path to latest checkpoint (default: none)') parser.add_argument('--model', type=str, default='UNET2D', choices=( 'VNET', 'VNET2', 'UNET3D', 'DENSENET1', 'DENSENET2', 'DENSENET3', 'HYPERDENSENET', "UNET2D")) parser.add_argument('--opt', type=str, default='sgd', choices=('sgd', 'adam', 'rmsprop')) args = parser.parse_args() args.save = '../saved_models/' + args.model + '_checkpoints/' + args.model + '_{}_{}_'.format( utils.datestr(), args.dataset_name) return args
def main(): args = get_arguments() seed = 1777777 torch.manual_seed(seed) if args.cuda: torch.cuda.manual_seed(seed) np.random.seed(seed) cudnn.deterministic = True cudnn.benchmark = True 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)
def main(): args = get_arguments() os.environ["CUDA_VISIBLE_DEVICES"] = "0,2" ## 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)
def get_arguments(): parser = argparse.ArgumentParser() parser.add_argument('--batchSz', type=int, default=4) parser.add_argument('--dataset_name', type=str, default="mrbrains4") parser.add_argument('--dataset_path', type=str, default="datasets") parser.add_argument('--dim', nargs="+", type=int, default=(128, 128, 48)) parser.add_argument('--nEpochs', type=int, default=200) parser.add_argument('--inChannels', type=int, default=3) parser.add_argument('--inModalities', type=int, default=3) parser.add_argument('--terminal_show_freq', default=50) parser.add_argument('--samples_train', type=int, default=10) parser.add_argument('--samples_val', type=int, default=10) parser.add_argument('--classes', type=int, default=2) parser.add_argument('--threshold', default=0.1, type=float) parser.add_argument('--augmentation', default='no', type=str, help='Tensor normalization: options max, mean, global') parser.add_argument('--normalization', default='global_mean', type=str, help='Tensor normalization: options max, mean, global') parser.add_argument('--resume', default='', type=str, metavar='PATH', help='path to latest checkpoint (default: none)') parser.add_argument( '--split', default=0.9, type=float, help='Select percentage of training data(default: 0.8)') parser.add_argument('--lr', default=1e-3, type=float, help='learning rate (default: 1e-3)') parser.add_argument('--cuda', action='store_true', default=False) parser.add_argument('--model', type=str, default='UNET3D', choices=('VNET', 'VNET2', 'UNET3D', 'DENSENET1', 'DENSENET2', 'DENSENET3', 'HYPERDENSENET')) parser.add_argument('--opt', type=str, default='sgd', choices=('sgd', 'adam', 'rmsprop')) parser.add_argument('--log_dir', type=str, default='../runs/') args = parser.parse_args() args.save = '../saved_models/' + args.model + '_checkpoints/' + args.model + '_{}_{}_'.format( utils.datestr(), args.dataset_name) return args
def get_arguments(): parser = argparse.ArgumentParser() parser.add_argument('--batchSz', type=int, default=2) parser.add_argument('--dataset_name', type=str, default="iseg2019") parser.add_argument('--dim', nargs="+", type=int, default=(32, 32, 32)) parser.add_argument('--nEpochs', type=int, default=200) parser.add_argument('--classes', type=int, default=4) parser.add_argument('--samples_train', type=int, default=10) parser.add_argument('--samples_val', type=int, default=10) parser.add_argument('--inChannels', type=int, default=2) parser.add_argument('--inModalities', type=int, default=2) parser.add_argument('--threshold', default=0.0001, type=float) parser.add_argument('--terminal_show_freq', default=50) parser.add_argument('--augmentation', action='store_true', default=True) parser.add_argument('--normalization', default='full_volume_mean', type=str, help='Tensor normalization: options ,max_min,', choices=('max_min', 'full_volume_mean', 'brats', 'max', 'mean')) parser.add_argument('--fold_id', default='1', type=str, help='Select subject for fold validation') parser.add_argument('--lr', default=1e-3, type=float, help='learning rate (default: 1e-3)') parser.add_argument( '--split', default=0.8, type=float, help='Select percentage of training data(default: 0.8)') parser.add_argument('--cuda', action='store_true', default=True) parser.add_argument('--loadData', default=True) parser.add_argument('--resume', default='', type=str, metavar='PATH', help='path to latest checkpoint (default: none)') parser.add_argument('--model', type=str, default='UNET3D', choices=('VNET', 'VNET2', 'UNET3D', 'DENSENET1', 'DENSENET2', 'DENSENET3', 'HYPERDENSENET')) parser.add_argument('--opt', type=str, default='sgd', choices=('sgd', 'adam', 'rmsprop')) parser.add_argument('--log_dir', type=str, default='../runs/') args = parser.parse_args() args.save = '../saved_models/' + args.model + '_checkpoints/' + args.model + '_{}_{}_'.format( utils.datestr(), args.dataset_name) return args
def get_arguments(): parser = argparse.ArgumentParser() parser.add_argument('--batchSz', type=int, default=1) parser.add_argument('--dataset_name', type=str, default="ribfrac") parser.add_argument('--dim', nargs="+", type=int, default=(64, 64, 64)) parser.add_argument('--nEpochs', type=int, default=250) parser.add_argument('--classes', type=int, default=6) parser.add_argument('--samples_train', type=int, default=1) parser.add_argument('--samples_val', type=int, default=1) parser.add_argument('--split', type=float, default=0.8) parser.add_argument('--inChannels', type=int, default=1) parser.add_argument('--inModalities', type=int, default=1) parser.add_argument('--fold_id', default='1', type=str, help='Select subject for fold validation') parser.add_argument('--lr', default=1e-2, type=float, help='learning rate (default: 1e-3)') parser.add_argument('--cuda', action='store_true', default=True) parser.add_argument('--resume', default='', type=str, metavar='PATH', help='path to latest checkpoint (default: none)') parser.add_argument('--model', type=str, default='UNET3D', choices=('VNET', 'VNET2', 'UNET3D', 'DENSENET1', 'DENSENET2', 'DENSENET3', 'HYPERDENSENET','DENSEVOXELNET')) parser.add_argument('--opt', type=str, default='sgd', choices=('sgd', 'adam', 'rmsprop')) parser.add_argument('--loadData', default=False) # params need to be set for test parser.add_argument('--pretrained', # default='/data/hejy/MedicalZooPytorch/saved_models/UNET3D_checkpoints/UNET3D_64x64x48_0.1_weight0.1/UNET3D_64x64x48_0.1_weight0.1_BEST.pth', # default = '/data/hejy/MedicalZooPytorch/saved_models/UNET3D_checkpoints/UNET3D_128x128x48_thresh0.1_sample1200_epoch600_fgbg/UNET3D_128x128x48_thresh0.1_sample1200_epoch600_fgbg_BEST.pth', # default='/data/hejy/MedicalZooPytorch/saved_models/UNET3D_checkpoints/UNET3D_128x128x48_thresh0.3_weight0.01_sample400/UNET3D_128x128x48_thresh0.3_weight0.01_sample400_BEST.pth', # default='/data/hejy/MedicalZooPytorch/saved_models/UNET3D_checkpoints/UNET3D_128x128x48_thresh0.3_weight0.01_sample400_epoch600_test_val+/UNET3D_128x128x48_thresh0.3_weight0.01_sample400_epoch600_test_val+_BEST.pth', # default='/data/hejy/MedicalZooPytorch/saved_models/DENSEVOXELNET_checkpoints/DENSEVOXELNET_128x128x48_thresh0.1_weight1_sample400_epoch600_augdata/DENSEVOXELNET_128x128x48_thresh0.1_weight1_sample400_epoch600_augdata_BEST.pth', # default='/data/hejy/MedicalZooPytorch/saved_models/UNET3D_checkpoints/UNET3D_128x128x48_thresh0.1_weight1_sample400_epoch600_augdata/UNET3D_128x128x48_thresh0.1_weight1_sample400_epoch600_augdata_BEST.pth', # default='/data/hejy/MedicalZooPytorch/saved_models/UNET3D_checkpoints/UNET3D_128x128x48_thresh0.1_sample1200_epoch600_fgbg/UNET3D_128x128x48_thresh0.1_sample1200_epoch600_fgbg_last_epoch.pth', # default = '/data/hejy/MedicalZooPytorch/saved_models/UNET3D_checkpoints/UNET3D_196x196x96_thresh0.1_weight1_sample400/UNET3D_196x196x96_thresh0.1_weight1_sample400_BEST.pth', default = '/data/hejy/MedicalZooPytorch_copy/saved_models/UNET3D_checkpoints/UNET3D_256x256x256_thresh0.8_weight1_sample1200/UNET3D_256x256x256_thresh0.8_weight1_sample1200_BEST.pth', # default = '/data/hejy/MedicalZooPytorch_2cls/saved_models/UNET3D_checkpoints/2cls_UNET3D_512x512x96_thresh0.6_weight1_sample200/2cls_UNET3D_512x512x96_thresh0.6_weight1_sample200_BEST.pth', # default='/data/hejy/MedicalZooPytorch/saved_models/UNET3D_checkpoints/UNET3D_128x128x48_thresh0.3_sample400_epoch600_test_val+_wce/UNET3D_128x128x48_thresh0.3_sample400_epoch600_test_val+_wce_BEST.pth', type=str, metavar='PATH', help='path to pretrained model') parser.add_argument('--nii_save_path', default='/data/hejy/MedicalZooPytorch_copy/saved_nii') parser.add_argument('--test_path', default="/data/beijing/dataset/MICCAI-RibFrac2020/ribfrac-val-images") # parser.add_argument('--test_path', default="/data/hejy/MedicalZooPytorch/datasets/MICCAI_2020_ribfrac/org/ribfrac-val-images") args = parser.parse_args() args.save = '/data/hejy/MedicalZooPytorch_copy/inference_checkpoints/' + args.model + '_checkpoints/' + args.model + '_{}_{}_'.format( utils.datestr(), args.dataset_name) args.tb_log_dir = '../runs/' return args
def __init__(self, args): name_model = args.log_dir + args.model + "_" + args.dataset_name + "_" + utils.datestr( ) self.writer = SummaryWriter(log_dir=args.log_dir + name_model, comment=name_model) utils.make_dirs(args.save) self.csv_train, self.csv_val = self.create_stats_files(args.save) self.dataset_name = args.dataset_name self.classes = args.classes self.label_names = dict_class_names[args.dataset_name] self.data = self.create_data_structure()
def get_arguments(): parser = argparse.ArgumentParser() parser.add_argument('--batchSz', type=int, default=1) parser.add_argument('--dataset_name', type=str, default="iseg2017") parser.add_argument('--dim', nargs="+", type=int, default=(32, 32, 32)) parser.add_argument('--nEpochs', type=int, default=250) parser.add_argument('--classes', type=int, default=4) parser.add_argument('--samples_train', type=int, default=10) parser.add_argument('--samples_val', type=int, default=10) parser.add_argument('--inChannels', type=int, default=2) parser.add_argument('--inModalities', type=int, default=2) parser.add_argument('--fold_id', default='1', type=str, help='Select subject for fold validation') parser.add_argument('--lr', default=1e-3, type=float, help='learning rate (default: 1e-3)') parser.add_argument('--cuda', action='store_true', default=False) parser.add_argument('--resume', default='', type=str, metavar='PATH', help='path to latest checkpoint (default: none)') parser.add_argument('--model', type=str, default='DENSEVOXELNET', choices=('VNET', 'VNET2', 'UNET3D', 'DENSENET1', 'DENSENET2', 'DENSENET3', 'HYPERDENSENET')) parser.add_argument('--opt', type=str, default='sgd', choices=('sgd', 'adam', 'rmsprop')) parser.add_argument( '--log_dir', type=str, default= '/home/papastrat/PycharmProjects/MedicalZooPytorch/runs/lias_test_run') args = parser.parse_args() args.save = '../saved_models/' + args.model + '_checkpoints/' + args.model + '_{}_{}_'.format( datestr(), args.dataset_name) return args
def main(): args = get_arguments() utils.make_dirs(args.save) train_f, val_f = utils.create_stats_files(args.save) name_model = args.model + "_" + args.dataset_name + "_" + utils.datestr() writer = SummaryWriter(log_dir='../runs/' + name_model, comment=name_model) best_prec1 = 100. 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: torch.cuda.manual_seed(seed) model = model.cuda() print("Model transferred in GPU.....") print("START TRAINING...") for epoch in range(1, args.nEpochs + 1): train_stats = train.train_dice(args, epoch, model, training_generator, optimizer, criterion, train_f, writer) val_stats = train.test_dice(args, epoch, model, val_generator, criterion, val_f, writer) utils.write_train_val_score(writer, epoch, train_stats, val_stats) model.save_checkpoint(args.save, epoch, val_stats[0], optimizer=optimizer) # if epoch % 5 == 0: # utils.visualize_no_overlap(args, full_volume, affine, model, epoch, DIM, writer) #utils.save_model(model, args, val_stats[0], epoch, best_prec1) train_f.close() val_f.close()
def __init__(self, args): name_model = args.model + "_" + args.dataset_name + "_" + datestr() self.writer = SummaryWriter(log_dir=args.tb_log_dir, comment=name_model) # self.step = 0 # self.mode = '' self.csv_train, self.csv_val = self.create_stats_files(args.save) self.dataset_name = args.dataset_name self.label_names = dict_class_names[args.dataset_name] self.data = { "train": dict((label, 0.0) for label in self.label_names), "val": dict((label, 0.0) for label in self.label_names) } self.data['train']['loss'] = 0.0 self.data['val']['loss'] = 0.0 self.data['train']['count'] = 1.0 self.data['val']['count'] = 1.0 self.data['train']['dsc'] = 0.0 self.data['val']['dsc'] = 0.0
def main(): args = get_arguments() utils.make_dirs(args.save) train_f, val_f = utils.create_stats_files(args.save) name_model = args.model + "_" + args.dataset_name + "_" + utils.datestr() writer = SummaryWriter(log_dir='../runs/' + name_model, comment=name_model) best_pred = 1.01 samples_train = 200 samples_val = 200 training_generator, val_generator, full_volume, affine = medical_loaders.generate_datasets( args, path='.././datasets', samples_train=samples_train, samples_val=samples_val) model, optimizer = medzoo.create_model(args) criterion = medzoo.DiceLoss2D(args.classes) if args.cuda: torch.cuda.manual_seed(seed) model = model.cuda() for epoch in range(1, args.nEpochs + 1): train_stats = train.train_dice(args, epoch, model, training_generator, optimizer, criterion, train_f, writer) val_stats = train.test_dice(args, epoch, model, val_generator, criterion, val_f, writer) utils.write_train_val_score(writer, epoch, train_stats, val_stats) best_pred = utils.save_model(model=model, args=args, dice_loss=val_stats[0], epoch=epoch, best_pred_loss=best_pred) train_f.close() val_f.close()
# globals perfs = [] # actual run if __name__ == "__main__": # parse args out parser = argparse.ArgumentParser() parser.add_argument("identifier", type=str, help="A uniquely identifying string for this file with format [init_weights_class]_[training_class]") parser.add_argument("pos_class", type=str, help="Which folder in data/Flickr_2800/ to load for training") parser.add_argument('-t', '--transplant', type=str, help='The identifier of the transplant to start from') parser.add_argument('-l', '--lesion_indicator', type=str, default='') args = parser.parse_args() # load user configured constants if args.lesion_indicator is not '': IDENTIFIER = args.identifier + '_t' + args.lesion_indicator + utils.datestr() else: IDENTIFIER = args.identifier + utils.datestr() POSITIVE_IMAGE_DIR = os.path.join('data/Flickr_2800', args.pos_class) # let the user know what we're up to log.log("Training " + IDENTIFIER + " FROM " + POSITIVE_IMAGE_DIR) if args.transplant is not None: log.log("(Starting from " + args.transplant + "_t" + args.lesion_indicator + ")") else: log.log("(Starting from <blank net, random weights>)") # train it all with AlexNet() as alexnet: # Load data