示例#1
0
            app = "_" + str(time.time())
            model_file_raw += app
        model_file = model_file_raw + ".h5"

        # create tensorflow graph session
        graph = tf.Graph()
        with tf.Session(graph=graph):

            model = deep_learning.create_model(x_train, y_train,
                                               config["activation_fn"],
                                               config["loss_fn"])
            deep_learning.dl_save_model(model, model_file)
            deep_learning.eval_write_info(model, x_eval, y_eval, model_file, 0,
                                          0)

            acc = deep_learning.eval_model(model, x_eval, y_eval, sizex[1],
                                           False)

            if acc > top_acc:
                top_acc = acc
                top_model_filename = model_file_raw

            if i == n_reps - 1:
                if save_best_model:
                    copy2(top_model_filename + ".h5",
                          top_model_filename + "_top.h5")
                    copy2(top_model_filename + ".h5.txt",
                          top_model_filename + "_top.h5.txt")

        # K.clear_session()
    y = prep.encode(prep.adapt_input(y))

X = np.array(X)

sizex = np.shape(X)
sizey = np.shape(y)

print("refactored: ")
print(sizex)
print(sizey)

# create tensorflow graph session
tfgraph = tf.Graph()
with tf.Session(graph=tfgraph):
    model = deep_learning.dl_load_model(model_file)
    acc = deep_learning.eval_model(model, X, y, sizex[1], use_rnn)

    # make probability predictions with the model
    predictions = deep_learning.predict_model_RNN(model, X)
    sizep = np.shape(predictions)

    print("prediction shape: ")
    print(sizep)

    if config["one_hot_encoding"]:
        predictions = np.reshape(predictions, (sizep[0], sizep[2]))
        sizep = np.shape(predictions)
        print("reshape predictions: ")
        print(sizep)

    predictions = deep_learning.binarize_predictions_max(predictions)
示例#3
0
            train_percent = config["train_percent"]
            train_percent = 0

            x_train, y_train = classifiers.split_dataset_train(
                x, y, train_percent)

            x_eval, y_eval = classifiers.split_dataset_test(
                x, y, train_percent)

            # acc = deep_learning.eval_model(model, x_train, y_train, sizex[1])

            # results_train.append(
            #     [str(i + 1), str(j + 1), model_file, filename, str(acc*100)])

            acc = deep_learning.eval_model(
                model, x_eval, y_eval, sizex[1], use_rnn)

            results_test.append(
                [str(i + 1), str(j + 1), model_file, filename, str(acc*100)])

            print("model: " + model_file + "\tdataset: " +
                  data_file + "\tacc (test):" + str(acc))

# with open(root_data_folder + "/output/" + "cross_check_deep_train.csv", "w") as f:
#     for r in results_train:
#         f.write(",".join(r) + ",\n")
if use_rnn:
    output_file = "cross_check_deep_2_rnn_test.csv"
else:
    output_file = "cross_check_deep_1_test.csv"
示例#4
0
    for i in range(n_reps):
        print("evaluating model rep: " + str(i) + "/" + str(n_reps))

        # session = K.get_session()
        model_file = root_crt_model_folder + "/" + model_filenames[fn]
        model_file_raw = model_file
        model_file_raw += "_" + str(i+1)
        model_file = model_file_raw + ".h5"

        # create tensorflow graph session
        graph = tf.Graph()
        with tf.Session(graph=graph):

            model = deep_learning.dl_load_model(model_file)

            acc_train = deep_learning.eval_model(
                model, x_train, y_train, sizex[1], use_rnn)

            dt = time.time()
            acc_test = deep_learning.eval_model(
                model, x_eval, y_eval, sizex[1], use_rnn)
            dt = time.time() - dt

            if acc_train > top_train:
                top_train = acc_train

            if acc_test > top_test:
                top_test = acc_test

            if dt > top_test_dt:
                top_test_dt = dt