コード例 #1
0
ファイル: ghnet_al.py プロジェクト: zll302/PowerAI
    n_epochs = 10
    n_al_epochs = 10
    only_real = True
    y_columns = list(range(data_set.y.shape[1]))
    y_columns = [2, 11, 23]
    net.build_multi_reg_k(len(y_columns),
                          activation=tf.keras.layers.LeakyReLU())
    net1.build_multi_reg_k(len(y_columns),
                           activation=tf.keras.layers.LeakyReLU())
    data_set.split_dataset_random(train_perc=0.0,
                                  val_perc=0.1,
                                  notused_perc=0.9)
    data_set.make_dataset_tensors(y_columns=y_columns, only_real=only_real)
    val_sample_size = data_set.val_labels.shape[0]
    validation_steps = val_sample_size // n_batch
    val_gen = data_set.dataset_generator_multi(data_set.val_datas,
                                               data_set.val_labels, n_batch)

    for al in range(n_al_epochs):
        al_res = dataset_predict(net.pre_model, data_set, role=0)[:, 1]
        al_res = al_res.reshape((-1, len(y_columns)))
        al_res1 = dataset_predict(net1.pre_model, data_set, role=0)[:, 1]
        al_res1 = al_res1.reshape((-1, len(y_columns)))
        delta = np.abs(al_res - al_res1).mean(axis=1)
        al_as = delta.argsort()[::-1]
        new_train_num = min(np.sum(delta > 0.02), 200)
        idx = data_set.notused_indices[al_as[:new_train_num]]
        data_set.sample_prop.role[idx] = 1
        print("add %d new train samples." % new_train_num)
        data_set.make_dataset_tensors(y_columns=y_columns, only_real=only_real)

        train_sample_size = data_set.train_labels.shape[0]
コード例 #2
0
ファイル: ghnet_runner.py プロジェクト: zll302/PowerAI
            dt_test_begin = datetime.datetime(2018, 8, 26)
            dt_test_end = datetime.datetime(2018, 9, 1) - datetime.timedelta(seconds=1)
            ids = data_set.split_dataset_dt(dt_train_begin=dt_train_begin,
                                            dt_train_end=dt_train_end,
                                            dt_test_begin=dt_test_begin,
                                            dt_test_end=dt_test_end,
                                            val_perc=0.1)
        assert (0 in ids) and (1 in ids)
        data_set.make_dataset_tensors(y_columns=y_columns, only_real=only_real)
        train_data, train_labels, _ = data_set.get_dataset(0)
        train_sample_size = train_labels.shape[0]
        steps_per_epoch = train_sample_size // n_batch
        val_data, val_labels, _ = data_set.get_dataset(1)
        val_sample_size = val_labels.shape[0]
        validation_steps = val_sample_size // n_batch
        train_gen = data_set.dataset_generator_multi(train_data, train_labels, n_batch)
        val_gen = data_set.dataset_generator_multi(val_data, val_labels, n_batch)
        dt_run_start = datetime.datetime.now()
        with timer("Timer training"):
            history = net.train_model.fit_generator(train_gen,
                                                    epochs=n_epochs,
                                                    steps_per_epoch=steps_per_epoch,
                                                    validation_data=val_gen,
                                                    validation_steps=validation_steps)
        test_labels, pre = dataset_predict(net.pre_model, data_set, role=2)
        save_model(res_path, args.res_type, net.pre_model, suffix='pb')
        # save_model(res_path, args.res_type, net.pre_model, suffix='json')
        write_input(data_set, res_path + "/input.txt")
        write_output(data_set.y.columns[y_columns], res_path + "/output.txt")
        sys.exit(0)