本文整理匯總了Python中keras.models.save_model方法的典型用法代碼示例。如果您正苦於以下問題:Python models.save_model方法的具體用法?Python models.save_model怎麽用?Python models.save_model使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類keras.models
的用法示例。
在下文中一共展示了models.save_model方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: save_model
# 需要導入模塊: from keras import models [as 別名]
# 或者: from keras.models import save_model [as 別名]
def save_model(self, folder_path, file_name = None):
if file_name is None:
file_name = self.RECOMMENDER_NAME
self._print("Saving model in file '{}'".format(folder_path + file_name))
self.model.save_weights(folder_path + file_name + "_weights", overwrite=True)
data_dict_to_save = {
"n_users": self.n_users,
"n_items": self.n_items,
"mf_dim": self.mf_dim,
"layers": self.layers,
"reg_layers": self.reg_layers,
"reg_mf": self.reg_mf,
}
dataIO = DataIO(folder_path=folder_path)
dataIO.save_data(file_name=file_name, data_dict_to_save = data_dict_to_save)
self._print("Saving complete")
示例2: on_epoch_end
# 需要導入模塊: from keras import models [as 別名]
# 或者: from keras.models import save_model [as 別名]
def on_epoch_end(self, epoch, logs={}):
if (epoch + 1) % self.period_of_epochs == 0:
# Filenames
baseHDF5Filename = "ModelChkpt{:06d}.hdf5".format(epoch+1)
baseYAMLFilename = "ModelChkpt{:06d}.yaml".format(epoch+1)
hdf5Filename = os.path.join(self.chkptsdir, baseHDF5Filename)
yamlFilename = os.path.join(self.chkptsdir, baseYAMLFilename)
# YAML
yamlModel = self.model.to_yaml()
with open(yamlFilename, "w") as yamlFile:
yamlFile.write(yamlModel)
# HDF5
KM.save_model(self.model, hdf5Filename)
with H.File(hdf5Filename, "r+") as f:
f.require_dataset("initialEpoch", (), "uint64", True)[...] = int(epoch+1)
f.flush()
# Symlink to new HDF5 file, then atomically rename and replace.
os.symlink(baseHDF5Filename, self.linkFilename+".rename")
os.rename (self.linkFilename+".rename",
self.linkFilename)
# Print
L.getLogger("train").info("Saved checkpoint to {:s} at epoch {:5d}".format(hdf5Filename, epoch+1))
#
# Save record-best models.
#
示例3: save_model_to_hdf5_group
# 需要導入模塊: from keras import models [as 別名]
# 或者: from keras.models import save_model [as 別名]
def save_model_to_hdf5_group(model, f):
# Use Keras save_model to save the full model (including optimizer
# state) to a file.
# Then we can embed the contents of that HDF5 file inside ours.
tempfd, tempfname = tempfile.mkstemp(prefix='tmp-betago')
try:
os.close(tempfd)
save_model(model, tempfname)
serialized_model = h5py.File(tempfname, 'r')
root_item = serialized_model.get('/')
serialized_model.copy(root_item, f, 'kerasmodel')
serialized_model.close()
finally:
os.unlink(tempfname)
示例4: _patch_io_calls
# 需要導入模塊: from keras import models [as 別名]
# 或者: from keras.models import save_model [as 別名]
def _patch_io_calls(Network, Sequential, keras_saving):
try:
if Sequential is not None:
Sequential._updated_config = _patched_call(Sequential._updated_config,
PatchKerasModelIO._updated_config)
if hasattr(Sequential.from_config, '__func__'):
# noinspection PyUnresolvedReferences
Sequential.from_config = classmethod(_patched_call(Sequential.from_config.__func__,
PatchKerasModelIO._from_config))
else:
Sequential.from_config = _patched_call(Sequential.from_config, PatchKerasModelIO._from_config)
if Network is not None:
Network._updated_config = _patched_call(Network._updated_config, PatchKerasModelIO._updated_config)
if hasattr(Sequential.from_config, '__func__'):
# noinspection PyUnresolvedReferences
Network.from_config = classmethod(_patched_call(Network.from_config.__func__,
PatchKerasModelIO._from_config))
else:
Network.from_config = _patched_call(Network.from_config, PatchKerasModelIO._from_config)
Network.save = _patched_call(Network.save, PatchKerasModelIO._save)
Network.save_weights = _patched_call(Network.save_weights, PatchKerasModelIO._save_weights)
Network.load_weights = _patched_call(Network.load_weights, PatchKerasModelIO._load_weights)
if keras_saving is not None:
keras_saving.save_model = _patched_call(keras_saving.save_model, PatchKerasModelIO._save_model)
keras_saving.load_model = _patched_call(keras_saving.load_model, PatchKerasModelIO._load_model)
except Exception as ex:
LoggerRoot.get_base_logger(TensorflowBinding).warning(str(ex))
示例5: _save
# 需要導入模塊: from keras import models [as 別名]
# 或者: from keras.models import save_model [as 別名]
def _save(original_fn, self, *args, **kwargs):
if hasattr(self, 'trains_out_model'):
self.trains_out_model._processed = False
original_fn(self, *args, **kwargs)
# no need to specially call, because the original save uses "save_model" which we overload
if not hasattr(self, 'trains_out_model') or not self.trains_out_model._processed:
PatchKerasModelIO._update_outputmodel(self, *args, **kwargs)
示例6: save_model
# 需要導入模塊: from keras import models [as 別名]
# 或者: from keras.models import save_model [as 別名]
def save_model(self, folder_path, file_name = None):
if file_name is None:
file_name = self.RECOMMENDER_NAME
self._print("Saving model in file '{}'".format(folder_path + file_name))
self.model.save_weights(folder_path + file_name + "_weights", overwrite=True)
data_dict_to_save = {
"n_users": self.n_users,
"n_items": self.n_items,
"path_nums": self.path_nums,
"timestamps": self.timestamps,
"length": self.length,
"layers": self.layers,
"reg_layes": self.reg_layes,
"latent_dim": self.latent_dim,
"reg_latent": self.reg_latent,
"learning_rate": self.learning_rate,
}
dataIO = DataIO(folder_path=folder_path)
dataIO.save_data(file_name=file_name, data_dict_to_save = data_dict_to_save)
self._print("Saving complete")