Пример #1
0
def main():
    global best_val_score
    gl = get_grid_list()
    for g in gl:
        best_val_score = 0.0
        conf = EfficientNetConfig(depth=g[0], width=g[1], resolution=g[2], num_classes=10)
        run_name = conf_to_name(conf)

        run = wandb.init(project='EfficientNet_small', reinit=True)
        run.name = run_name
        run.save()

        cur_model = EfficientNet(conf)
        cur_model.cuda()

        wandb.watch(cur_model)

        train(cur_model, run_name)
        print(run_name, best_val_score)
        run.finish()
        scores = model(data)
        pred = scores.data.max(1)[1]
        test_correct += pred.eq(target.data).cpu().sum()
    print("Predicted {} out of {} correctly".format(test_correct,
                                                    total_examples))
    return 100.0 * test_correct / (float(total_examples))


if __name__ == '__main__':
    torch.cuda.device(0)
    model = EfficientNet(1.0, 1.0)

    config = CONFIG()

    model = model.cuda()

    avg_loss = list()
    best_accuracy = 0.0

    optimizer = optim.SGD(model.parameters(),
                          lr=LEARNING_RATE,
                          momentum=config.momentum,
                          weight_decay=config.weight_decay)

    train_acc, val_acc = list(), list()

    for i in range(1, EPOCHS + 1):
        train_acc.append(train(i))
        val_acc.append(val())
        save_model(model, i)