Ejemplo n.º 1
0
def main(controller, cosine_annealing_scheduler):
    running_reward = 0
    child = Child(dropout_rate=float(args.dropout),
                  use_auxiliary=args.use_auxiliary).to(device)

    child_optimizer = optim.SGD(child.parameters(),
                                lr=0.05,
                                momentum=0.9,
                                weight_decay=1e-4,
                                nesterov=True)
    cosine_lr_scheduler = cosine_annealing_scheduler(child_optimizer, lr=0.05)

    for epoch in range(150):
        cosine_lr_scheduler.step()
        child = train_child(epoch, controller, child, child_optimizer)
        torch.save(child.state_dict(), './save_model/child.pth')
        torch.save(controller.state_dict(), './save_model/controller.pth')

        if epoch < 150 - 1:
            controller_model, running_reward = train_controller(
                controller, child, running_reward)

    final_model = model
    final_acc = test_final_model(final_model)
    print('training is done. Final accuarcy is ', final_acc)
Ejemplo n.º 2
0
                                          batch_size=100,
                                          shuffle=False,
                                          num_workers=args.num_worker)

# there are 10 classes so the dataset name is cifar-10
classes = ('plane', 'car', 'bird', 'cat', 'deer', 'dog', 'frog', 'horse',
           'ship', 'truck')

print('==> Making model..')

criterion = nn.CrossEntropyLoss()
normal_arc = best_reward_arc[0]
reduction_arc = best_reward_arc[1]

child = Child().to(device)
child_optimizer = optim.SGD(child.parameters(),
                            lr=0.05,
                            momentum=0.9,
                            weight_decay=1e-4,
                            nesterov=True)
cosine_lr_scheduler = cosine_annealing_scheduler(child_optimizer, lr=0.05)

best_acc = 0
for epoch in range(300):
    child.train()
    cosine_lr_scheduler.step()

    train_loss = 0
    correct = 0
    total = 0
    for batch_idx, (inputs, targets) in enumerate(train_loader):