def main(): models = ['resnet18', 'resnet34', 'resnet101', 'resnet152'] layers = ['layer4', 'layer3', 'layer2', 'layer1'] for model_name in models: sample_model = experiment('whole', model_name, num_classes=4, pretrained=True) all_experiments = [] for l in layers: all_experiments += get_experiments_per_layer(sample_model, l) all_experiments += ['whole'] for exp in all_experiments: parser = argparse.ArgumentParser(description='Microscopy Classification CLEF') parser.add_argument('--batch-size', type=int, default=32, metavar='N', help='input batch size for training (default: 32)') parser.add_argument('--test-batch-size', type=int, default=32, metavar='N', help='input batch size for testing (default: 1000)') parser.add_argument('--epochs', type=int, default=1, metavar='N', help='number of epochs to train (default: 10)') parser.add_argument('--lr', type=float, default=1e-3, metavar='LR', help='learning rate (default: 0.001)') parser.add_argument('--seed', type=int, default=443, metavar='S', help='random seed (default: 443)') parser.add_argument('--patience', type=int, default=5, metavar='N', help='how many epochs to wait before stopping a non-improving execution') parser.add_argument('--num-workers', type=int, default=16, metavar='N', help='processors for data loading tasks') parser.add_argument('--num-output-classes', type=int, default=4, metavar='N', help='number of classes in the dataset') parser.add_argument('--csv-path', type=str, default='/workspace/labels/microscopy.csv', help='location of input images') parser.add_argument('--out-dir', type=str, default='/workspace/outputs', help='location for output data') parser.add_argument('--project_name', type=str, default='microscopy', help='Project name on Wandb') parser.add_argument('--architecture', type=str, default='resnet18', help='Highlevel description of the deep learning model used') parser.add_argument('--experiment', type=str, default='fc', help='Experiment variation') parser.add_argument('--pretrained', type=int, default='1', help='pretrain on imagenet') parser.add_argument('--infra', type=str, default='', help='Description of the infrastructure used for training') parser.add_argument('--notes', type=str, default='', help='Any particular note about the run') parser.add_argument('--augmentation', type=int, default='1', help='Use data augmentation') parser.add_argument('--weight-sampler', type=int, default='1', help='Weight sampling for unbalanced set') parser.add_argument('--weight-loss', type=int, default='1', help='Apply a weighted loss function to fight unbalanced dataset') args = parser.parse_args() # update args args.architecture = model_name args.experiment = exp args.lr = 5e-6 args.epochs = 100 args.patience = 100 # all with weight loss and weight sampler and augmentation (see defaults) provider = MicroscopyTrainDataLoader(args.csv_path, seed=args.seed) model = experiment(args.experiment, args.architecture, num_classes=args.num_output_classes, pretrained= (args.pretrained == 1)) args.augmentation = (args.augmentation == 1) args.weight_sampler = (args.weight_sampler == 1) args.weight_loss = (args.weight_loss == 1) run = ExperimentalRun(model, provider, args, notes=args.notes, tags=['clef', 'microscopy']) run.train()
def main(): parser = argparse.ArgumentParser(description='Chart Image Classification') parser.add_argument('--batch-size', type=int, default=32, metavar='N', help='input batch size for training (default: 32)') parser.add_argument('--test-batch-size', type=int, default=32, metavar='N', help='input batch size for testing (default: 1000)') parser.add_argument('--epochs', type=int, default=10, metavar='N', help='number of epochs to train (default: 10)') parser.add_argument('--lr', type=float, default=1e-3, metavar='LR', help='learning rate (default: 0.001)') parser.add_argument('--seed', type=int, default=443, metavar='S', help='random seed (default: 443)') #parser.add_argument('--log-interval', type=int, default=10, metavar='N', help='how many batches to wait before logging training status') parser.add_argument( '--patience', type=int, default=5, metavar='N', help='how many epochs to wait before stopping a non-improving execution' ) parser.add_argument('--num-workers', type=int, default=16, metavar='N', help='processors for data loading tasks') parser.add_argument('--num-output-classes', type=int, default=10, metavar='N', help='number of classes in the dataset') parser.add_argument('--dataset-path', type=str, default='./data', help='location of input images') parser.add_argument('--labels-path', type=str, default='../labels_task1.csv', help='location of labels for task') parser.add_argument('--out-dir', type=str, default='./outputs', help='location for output data') parser.add_argument('--project_name', type=str, default='chart', help='Project name on Wandb') parser.add_argument( '--architecture', type=str, default='', help='Highlevel description of the deep learning model used') parser.add_argument( '--infra', type=str, default='', help='Description of the infrastructure used for training') parser.add_argument('--notes', type=str, default='', help='Any particular note about the run') args = parser.parse_args() classes = [ 'Donut', 'Grouped horizontal bar', 'Grouped vertical bar', 'Horizontal box', 'Line', 'Pie', 'Scatter', 'Stacked horizontal bar', 'Stacked vertical bar', 'Vertical box' ] provider = DataProprocessing(args.dataset_path, None, args.labels_path, seed=args.seed) model = models.resnet50(pretrained=False) # Reset the last layer num_ftrs = model.fc.in_features model.fc = nn.Linear(num_ftrs, args.num_output_classes) run = ExperimentalRun(model, provider, args, notes=args.notes, tags=['chart', 'image classification']) run.train()
def main(): parser = argparse.ArgumentParser( description='Microscopy Classification CLEF') parser.add_argument('--batch-size', type=int, default=32, metavar='N', help='input batch size for training (default: 32)') parser.add_argument('--test-batch-size', type=int, default=32, metavar='N', help='input batch size for testing (default: 1000)') parser.add_argument('--epochs', type=int, default=1, metavar='N', help='number of epochs to train (default: 10)') parser.add_argument('--lr', type=float, default=1e-3, metavar='LR', help='learning rate (default: 0.001)') parser.add_argument('--seed', type=int, default=443, metavar='S', help='random seed (default: 443)') parser.add_argument( '--patience', type=int, default=5, metavar='N', help='how many epochs to wait before stopping a non-improving execution' ) parser.add_argument('--num-workers', type=int, default=16, metavar='N', help='processors for data loading tasks') parser.add_argument('--num-output-classes', type=int, default=4, metavar='N', help='number of classes in the dataset') parser.add_argument('--csv-path', type=str, default='/workspace/labels/microscopy.csv', help='location of input images') parser.add_argument('--out-dir', type=str, default='/workspace/outputs', help='location for output data') parser.add_argument('--project_name', type=str, default='microscopy', help='Project name on Wandb') parser.add_argument( '--architecture', type=str, default='resnet18', help='Highlevel description of the deep learning model used') parser.add_argument('--experiment', type=str, default='fc', help='Experiment variation') parser.add_argument('--pretrained', type=int, default='1', help='pretrain on imagenet') parser.add_argument( '--infra', type=str, default='', help='Description of the infrastructure used for training') parser.add_argument('--notes', type=str, default='', help='Any particular note about the run') parser.add_argument('--augmentation', type=int, default='0', help='Use data augmentation') parser.add_argument('--weight-sampler', type=int, default='0', help='Weight sampling for unbalanced set') parser.add_argument( '--weight-loss', type=int, default='0', help='Apply a weighted loss function to fight unbalanced dataset') args = parser.parse_args() provider = MicroscopyTrainDataLoader(args.csv_path, seed=args.seed) args.augmentation = (args.augmentation == 1) args.weight_sampler = (args.weight_sampler == 1) args.weight_loss = (args.weight_loss == 1) JSON_INPUT_PATH = "/workspace/src/experiments/microscopy/shallow-resnet50.json" with open(JSON_INPUT_PATH) as json_file: models = json.load(json_file) resnet50_4_2 = load_shallow_model('resnet50.layer4-2', models) resnet50_4_1 = load_shallow_model('resnet50.layer4-1', models) resnet50_4_0 = load_shallow_model('resnet50.layer4-0', models) resnet50_3_5 = load_shallow_model('resnet50.layer3-5', models) resnet50_3_4 = load_shallow_model('resnet50.layer3-4', models) resnet50_3_3 = load_shallow_model('resnet50.layer3-3', models) ensemble = MyEnsemble(resnet50_4_2, resnet50_4_1, resnet50_4_0, resnet50_3_5, resnet50_3_4, resnet50_3_3) for p in ensemble.parameters(): p.requires_grad = False for p in ensemble.classifier.parameters(): p.requires_grad = True run = ExperimentalRun(ensemble, provider, args, notes=args.notes, tags=['clef', 'microscopy', 'ensemble']) run.train()
def main(): parser = argparse.ArgumentParser( description='High Level Biomedical Image Classification') parser.add_argument('--batch-size', type=int, default=32, metavar='N', help='input batch size for training (default: 32)') parser.add_argument('--test-batch-size', type=int, default=32, metavar='N', help='input batch size for testing (default: 1000)') parser.add_argument('--epochs', type=int, default=10, metavar='N', help='number of epochs to train (default: 10)') parser.add_argument('--lr', type=float, default=1e-3, metavar='LR', help='learning rate (default: 0.001)') parser.add_argument('--seed', type=int, default=443, metavar='S', help='random seed (default: 443)') #parser.add_argument('--log-interval', type=int, default=10, metavar='N', help='how many batches to wait before logging training status') parser.add_argument( '--patience', type=int, default=5, metavar='N', help='how many epochs to wait before stopping a non-improving execution' ) parser.add_argument('--num-workers', type=int, default=16, metavar='N', help='processors for data loading tasks') parser.add_argument('--num-output-classes', type=int, default=10, metavar='N', help='number of classes in the dataset') parser.add_argument('--dataset-path', type=str, default='./data', help='location of input images') parser.add_argument('--labels-path', type=str, default='../labels_task1.csv', help='location of labels for task') parser.add_argument('--out-dir', type=str, default='./outputs', help='location for output data') parser.add_argument('--project_name', type=str, default='high-level biomedical modality', help='Project name on Wandb') parser.add_argument( '--architecture', type=str, default='', help='Highlevel description of the deep learning model used') parser.add_argument( '--infra', type=str, default='', help='Description of the infrastructure used for training') parser.add_argument('--notes', type=str, default='', help='Any particular note about the run') args = parser.parse_args() classes = [ 'MICROSCOPY', 'GRAPHICS', 'ORGANISMS', 'MOLECULAR', 'EXPERIMENTAL', 'OTHER' ] classes.sort() provider = TrainDataLoader(args.dataset_path, args.labels_path, classes, seed=args.seed) if args.architecture == 'resnet50': model = models.resnet50(pretrained=False) # Reset the last layer num_ftrs = model.fc.in_features model.fc = nn.Linear(num_ftrs, args.num_output_classes) elif args.architecture == 'resnet18': model = models.resnet18(pretrained=False) # Reset the last layer num_ftrs = model.fc.in_features model.fc = nn.Linear(num_ftrs, args.num_output_classes) elif args.architecture == 'resnet34': model = models.resnet34(pretrained=False) # Reset the last layer num_ftrs = model.fc.in_features model.fc = nn.Linear(num_ftrs, args.num_output_classes) elif args.architecture == 'efficientnet': # https://github.com/lukemelas/EfficientNet-PyTorch/issues/152 model = EfficientNet.from_pretrained( 'efficientnet-b0', num_classes=args.num_output_classes) for param in model.parameters(): param.requires_grad = False model._fc.weight.requires_grad = True model._fc.bias.requires_grad = True run = ExperimentalRun(model, provider, args, notes=args.notes, tags=['clef', 'modality']) run.train()