コード例 #1
0
    # テストデータの選択と生成
    test_dt = pre.load(dbpath=TEST_DATASET_TABLE_PATH)
    if args.base_result_ver is None:
        test_dt_indexes = dataselector.init_dataset_table_indexes()
    else:
        test_dt_indexes = dataselector.load_table_indexes(path=BASE_TEST_DT_INDEXES_PATH)
    selector = dataselector.DataSelector(test_dt, test_dt_indexes)
    test_dt_indexes, _ = selector.randomly_add(dataN=args.add_test, seed=args.seed)
    test = selector.out_selected_dataset()
    dataselector.save_dataset_table_indexes(test_dt_indexes, savepath=ADDED_TEST_DT_INDEXES_PATH)
    print("Number of test data: {0}".format(len(test)))
    testloader = torch.utils.data.DataLoader(test, batch_size=args.test_batch_size, shuffle=False, num_workers=2)


    # 学習と評価と保存
    model = training.process(trainloader, testloader, MODEL, args.epochs, args.lr, log_savepath=TRAIN_LOG_PATH)
    torch.save(model.state_dict(), MODEL_SAVE_PATH)

    # 学習結果の可視化
    train_losses, test_losses, train_accs, test_accs = tools.load_train_log(path=TRAIN_LOG_PATH)
    plot.plot_loss(train_losses, test_losses, savepath=LOSS_PLOT_RESULT_PATH)
    plot.plot_acc(train_accs, test_accs, savepath=ACC_PLOT_RESULT_PATH)

    # 訓練誤差収束速度の評価
    train_err_speed = eval_loss.eval_err_speed(train_losses)
    test_err_speed = eval_loss.eval_err_speed(test_losses)
    eval_loss.save(savepath=ERR_SPEED_SAVE_PATH, train_err_speed=train_err_speed, test_err_speed=test_err_speed)
    print("train loss error speed:  {0}".format(train_err_speed))
    print("test loss error speed:  {0}".format(test_err_speed))

    # 学習の設定値の記録
コード例 #2
0
    test_dt_indexes, _ = selector.randomly_add(dataN=args.add_test,
                                               seed=args.seed)
    test = selector.out_selected_dataset()
    dataselector.save_dataset_table_indexes(
        test_dt_indexes, savepath=ADDED_TEST_DT_INDEXES_PATH)
    print("Number of test data: {0}".format(len(test)))
    testloader = torch.utils.data.DataLoader(test,
                                             batch_size=args.test_batch_size,
                                             shuffle=False,
                                             num_workers=2)

    # 学習と評価
    model = training.process(trainloader,
                             testloader,
                             MODEL,
                             args.epochs,
                             args.lr,
                             lr_scheduling=LR_SCHEDULING,
                             log_savepath=TRAIN_LOG_PATH)

    # 学習結果の可視化
    train_losses, test_losses, train_accs, test_accs = tools.load_train_log(
        path=TRAIN_LOG_PATH)
    plot.plot_loss(train_losses, test_losses, savepath=LOSS_PLOT_RESULT_PATH)
    plot.plot_acc(train_accs, test_accs, savepath=ACC_PLOT_RESULT_PATH)

    # 訓練誤差収束速度の評価
    train_err_speed = eval_loss.eval_err_speed(train_losses)
    test_err_speed = eval_loss.eval_err_speed(test_losses)
    eval_loss.save(savepath=ERR_SPEED_SAVE_PATH,
                   train_err_speed=train_err_speed,
コード例 #3
0
                                              batch_size=args.batch_size,
                                              shuffle=True,
                                              num_workers=2)
    print("number of train data: {0}".format(len(train)))

    # テストデータの生成
    test = preprocess.load_dataset(dataset_dir=TEST_DIR,
                                   dataN=args.dataN // 4,
                                   imsize=(32, 32))
    testloader = torch.utils.data.DataLoader(test,
                                             batch_size=args.batch_size,
                                             shuffle=True,
                                             num_workers=2)
    print("number of train data: {0}".format(len(test)))

    # 学習と評価
    model = net.LeNet(2)
    model = training.process(trainloader,
                             testloader,
                             model,
                             args.epochs,
                             args.lr,
                             log_savepath=LOG_SAVEPATH)
    torch.save(model.state_dict(), MODEL_SAVEPATH)

    # 学習結果の可視化
    train_losses, test_losses, train_accs, test_accs = log_loader.load_log(
        path=LOG_SAVEPATH)
    plot.plot_loss(train_losses, test_losses, savepath=LOSS_SAVEPATH)
    plot.plot_acc(train_accs, test_accs, savepath=ACC_SAVEPATH)