本文整理汇总了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