batch_size=100,
                                         shuffle=False,
                                         num_workers=2)

classes = ('plane', 'car', 'bird', 'cat', 'deer', 'dog', 'frog', 'horse',
           'ship', 'truck')

# Model
print('==> Building model..')
checkpoint_dir = 'checkpoints'
if not os.path.exists('./checkpoints'):
    os.makedirs('./checkpoints')
if (args.model == 'resnet50'):
    net = resnet.ResNet50()
elif (args.model == 'resnet18'):
    net = resnet.ResNet18()

net = net.to(device)
if device == 'cuda':
    net = torch.nn.DataParallel(net)
    cudnn.benchmark = True

print('==> Resuming from checkpoint..')
#assert os.path.isdir(checkpoint_dir), 'Error: no checkpoint directory found!'
resume_file = '{}/{}'.format(checkpoint_dir, args.checkpoint)
assert os.path.isfile(resume_file)
checkpoint = torch.load(resume_file)
net.load_state_dict(checkpoint['net'])
net.eval()

Exemple #2
0
        return {'val_loss': avg_loss}

    def configure_optimizers(self):
        return torch.optim.Adam(self.parameters(), lr=.001)


ap = argparse.ArgumentParser(description="classifier")
ap.add_argument("--model", default="Classifier")
ap.add_argument("--max_epochs", default=10, type=int)
ap.add_argument("--tensorboard_log")
ns = ap.parse_args()

if ns.model == "lenet":
    model = lenet.LeNet()
if ns.model == "resnet":
    model = resnet.ResNet18()
elif ns.model == "resnetv2":
    model = resnetv2.PreActResNet18()
elif ns.model == "densenet":
    model = densenet.DenseNet121()
elif ns.model == "resnext":
    model = resnext.ResNeXt29_2x64d()
lit_model = Classifier(model)
dataset = datasets.CIFAR10(root='/home/julian/ImageDataSets/CIFAR10',
                           train=True,
                           download=False,
                           transform=transforms.Compose(
                               [transforms.ToTensor()]))
dataset_size = len(dataset)
print("Dataset size=", dataset_size)
training_size = np.round(dataset_size * 0.9).astype(int)