Python utils.save_model() Examples

The following are 3 code examples of utils.save_model(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module utils , or try the search function .
Example #1
Source File: evaluation.py    From PCANet with MIT License 6 votes vote down vote up
def evaluate_ensemble(train_set, test_set,
                      ensemble_params, transformer_params):
    (images_train, y_train), (images_test, y_test) = train_set, test_set

    model, accuracy, train_time, predict_time = run_pcanet_ensemble(
        ensemble_params, transformer_params,
        images_train, images_test, y_train, y_test
    )

    filename = model_filename()
    utils.save_model(model, join(pickle_dir, filename))

    params = {}
    params["ensemble-model"] = filename
    params["ensemble-accuracy"] = accuracy
    params["ensemble-train-time"] = train_time
    params["ensemble-predict-time"] = predict_time
    return params 
Example #2
Source File: evaluation.py    From PCANet with MIT License 6 votes vote down vote up
def evaluate_normal(train_set, test_set, transformer_params):
    (images_train, y_train), (images_test, y_test) = train_set, test_set

    model, accuracy, train_time, transform_time = run_pcanet_normal(
        transformer_params,
        images_train, images_test, y_train, y_test
    )

    filename = model_filename()
    utils.save_model(model, join(pickle_dir, filename))

    params = {}
    params["normal-model"] = filename
    params["normal-accuracy"] = accuracy
    params["normal-train-time"] = train_time
    params["normal-transform-time"] = transform_time
    return params 
Example #3
Source File: dl_models.py    From Sarcasm-Detection with MIT License 5 votes vote down vote up
def nn_bow_model(x_train, y_train, x_test, y_test, results, mode,
                 epochs=15, batch_size=32, hidden_units=50, save=False, plot_graph=False):
    # Build the model
    print("\nBuilding Bow NN model...")
    model = Sequential()
    model.add(Dense(hidden_units, input_shape=(x_train.shape[1],), activation='sigmoid'))
    model.add(Dense(1, activation='sigmoid'))
    model.summary()

    # Train using binary cross entropy loss, Adam implementation of Gradient Descent
    model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy', utils.f1_score])
    history = model.fit(x_train, y_train, batch_size=batch_size, epochs=epochs, verbose=1)

    if plot_graph:
        utils.plot_training_statistics(history, "/plots/bow_models/bow_%s_mode" % mode)

    # Evaluate the model
    loss, acc, f1 = model.evaluate(x_test, y_test, batch_size=batch_size)
    results[mode] = [loss, acc, f1]
    classes = model.predict_classes(x_test, batch_size=batch_size)
    y_pred = [item for c in classes for item in c]
    utils.print_statistics(y_test, y_pred)
    print("%d examples predicted correctly." % np.sum(np.array(y_test) == np.array(y_pred)))
    print("%d examples predicted 1." % np.sum(1 == np.array(y_pred)))
    print("%d examples predicted 0." % np.sum(0 == np.array(y_pred)))

    if save:
        json_name = path + "/models/bow_models/json_bow_" + mode + "_mode.json"
        h5_weights_name = path + "/models/bow_models/h5_bow_" + mode + "_mode.json"
        utils.save_model(model, json_name=json_name, h5_weights_name=h5_weights_name)


# A standard DNN used as a baseline