示例#1
0
print('---------- Networks architecture -------------')
print_network(model)
print('----------------------------------------------')

if opt.resume:
    if os.path.isfile(opt.resume):
        print("=> loading checkpoint '{}'".format(opt.resume))
        checkpoint = torch.load(opt.resume)
        opt.start_epoch = checkpoint["epoch"] + 1
        print(opt.start_epoch)
        model.load_state_dict(checkpoint["model"].state_dict())
    else:
        print("=> no checkpoint found at '{}'".format(opt.resume))

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

optimizer = optim.Adam(model.parameters(),
                       lr=opt.lr,
                       betas=(0.9, 0.999),
                       eps=1e-8)

for epoch in range(opt.start_epoch, opt.nEpochs + 1):
    train(model, epoch)

    # learning rate is decayed by a factor of 2 every 200 epochs
    if (epoch + 1) % 500 == 0:
        for param_group in optimizer.param_groups:
            param_group['lr'] /= 10.0
        print('Learning rate decay: lr={}'.format(
示例#2
0
features_test = np.load(
    os.path.join(config["load_dir"] + '/_feature_test_assigment.npy'))
features_test_crop = np.load(
    os.path.join(config["load_dir"] + '/_feature_test_assigment_crop.npy'))
if config["concatenate"]:
    features_test = np.concatenate((features_test, features_test_crop), axis=1)

#Model
model = Net(features_test.shape[1])

model.load_state_dict(state_dict['model'])
model.eval()
if use_cuda:
    print('Using GPU')
    model.cuda()
else:
    print('Using CPU')

for dossier, sous_dossiers, fichiers in os.walk(config["test_dir"]):
    for num, fichier in enumerate(fichiers):
        num_photo = df.loc[df['Id'] == fichier.split('.')[0]].index[0]
        data = torch.tensor(features_test[num])
        if use_cuda:
            data = data.cuda()
        output = model(data)
        prout, pred = torch.max(output.data, 0)
        df.Category[num_photo] = pred

df.to_csv('kaggle.csv', index=False)
print(