def save_model(model: keras.models.Model, topology: dict, filepath: str) -> None: """ Save a model to a file (tf.keras models only) The method save the model topology, as given as a Args: model: model object topology (dict): a dictionary of topology elements and their values filepath (str): path to save model """ with tempfile.NamedTemporaryFile(suffix='.h5', delete=True) as fd: model.save_weights(fd.name) model_weights = fd.read() data = {'model_weights': model_weights, 'model_topology': topology} with open(filepath, 'wb') as fp: pickle.dump(data, fp)
def save_checkpoint(self, fs: FSBase, model: keras.models.Model) -> None: with tempfile.NamedTemporaryFile(suffix=".h5") as tf: model.save_weights(tf.name) with open(tf.name, "rb") as fin: fs.writefile("model.h5", fin)
def save_weight(self, base_directory: str, model: keras.models.Model): print('saving weights...') model.save_weights(os.path.join(base_directory, self.weight_filename))