本文整理匯總了Python中utils.save_model方法的典型用法代碼示例。如果您正苦於以下問題:Python utils.save_model方法的具體用法?Python utils.save_model怎麽用?Python utils.save_model使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類utils
的用法示例。
在下文中一共展示了utils.save_model方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: evaluate_ensemble
# 需要導入模塊: import utils [as 別名]
# 或者: from utils import save_model [as 別名]
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
示例2: evaluate_normal
# 需要導入模塊: import utils [as 別名]
# 或者: from utils import save_model [as 別名]
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
示例3: nn_bow_model
# 需要導入模塊: import utils [as 別名]
# 或者: from utils import save_model [as 別名]
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