Exemplo n.º 1
0
def main():
    args = parse_args()

    global logger
    logger = Logger(args.logpath)

    torch.manual_seed(args.seed)
    use_cuda = not args.no_cuda and torch.cuda.is_available()
    device = torch.device("cuda" if use_cuda else "cpu")

    model = UNet2D(n_channels=1, n_classes=1).to(device)
    optimizer = optim.SGD(model.parameters(),
                          lr=args.lr,
                          momentum=args.momentum)
    criterion = SoftDiceLoss()

    dataset = IRCAD2D(args.datapath, tissue='bone', binarymask=True)
    print(f'Segmenting {dataset.tissue}')

    if args.resume:
        model, optimizer = load_checkpoint(model, optimizer, args.savepath,
                                           args.savefile)

    trainset, testset = train_valid_split(dataset)
    trainloader = DataLoader(trainset, batch_size=args.batch_size)
    testloader = DataLoader(testset, batch_size=args.batch_size)

    train_meters = {
        'loss': AverageMeter('trainloss', args.meterpath),
        'dice': AverageMeter('traindice', args.meterpath)
    }

    test_meters = {
        'loss': AverageMeter('testloss', args.meterpath),
        'dice': AverageMeter('testdice', args.meterpath)
    }

    for epoch in range(1, args.epochs + 1):
        train(args, model, device, trainloader, optimizer, epoch, train_meters,
              criterion, savepath, savefile)
        test(args, model, device, testloader, test_meters, epoch, criterion)

    train_meters['loss'].save()
    train_meters['dice'].save()
    test_meters['loss'].save()
    test_meters['dice'].save()
Exemplo n.º 2
0
def main():
    args = parse_args()

    global logger
    logger = Logger(args.logpath)

    torch.manual_seed(args.seed)

    start_gpu = f'cuda:{args.start_gpu}'
    end_gpu = f'cuda:{args.end_gpu}'

    model = ModelParallelUNet3D(n_channels=1, n_classes=1)
    optimizer = optim.SGD(model.parameters(),
                          lr=args.lr,
                          momentum=args.momentum)
    criterion = SoftDiceLoss()

    dataset = IRCAD3D(args.datapath, tissue='bone')
    print(f'Segmenting {dataset.tissue}')

    trainset, testset = train_valid_split(dataset)
    trainloader = DataLoader(trainset, batch_size=args.batch_size)
    testloader = DataLoader(testset, batch_size=args.batch_size)

    train_meters = {
        'loss': AverageMeter('trainloss', args.meterpath),
        'dice': AverageMeter('traindice', args.meterpath)
    }

    test_meters = {
        'loss': AverageMeter('testloss', args.meterpath),
        'dice': AverageMeter('testdice', args.meterpath)
    }

    for epoch in range(1, args.epochs + 1):
        train(args, model, start_gpu, end_gpu, trainloader, optimizer, epoch,
              train_meters, criterion)
        test(args, model, start_gpu, end_gpu, testloader, test_meters, epoch,
             criterion)

    train_meters['loss'].save()
    train_meters['dice'].save()
    test_meters['loss'].save()
    test_meters['dice'].save()
Exemplo n.º 3
0
def main():
    print(f'Kicking off.')
    args = parse_args()

    global logger
    logger = Logger(args.logpath)

    torch.manual_seed(args.seed)
    use_cuda = not args.no_cuda and torch.cuda.is_available()
    device = torch.device("cuda" if use_cuda else "cpu")

    model = UNet2D(n_channels=1, n_classes=1).to(device)
    optimizer = optim.SGD(model.parameters(),
                          lr=args.lr,
                          momentum=args.momentum)
    criterion = SoftDiceLoss()
    print('loading data...')

    dataset = AAPM(args.datapath)
    trainset, testset = train_valid_split(dataset)
    trainloader = DataLoader(trainset, batch_size=args.batch_size)
    testloader = DataLoader(testset, batch_size=args.batch_size)

    train_meters = {
        'loss': AverageMeter('trainloss', args.meterpath),
        'dice': AverageMeter('traindice', args.meterpath)
    }

    test_meters = {
        'loss': AverageMeter('testloss', args.meterpath),
        'dice': AverageMeter('testdice', args.meterpath)
    }

    for epoch in range(1, args.epochs + 1):
        train(args, model, device, trainloader, optimizer, epoch, train_meters,
              criterion)
        test(args, model, device, testloader, test_meters, epoch, criterion)

    train_meters['loss'].save()
    train_meters['dice'].save()
    test_meters['loss'].save()
    test_meters['dice'].save()