Exemplo n.º 1
0
def save(directory: str,
         name: str,
         active_model: keras.models.Model,
         target_model: keras.models.Model,
         memory=None):
    if not os.path.isdir(directory):
        os.mkdir(directory)
    active_model.save("{}/{}_active.h5f".format(directory, name))
    target_model.save("{}/{}_target.h5f".format(directory, name))
    if memory is not None:
        with open("{}/{}_memory.obj".format(directory, name), 'wb') as handler:
            pickle.dump(memory, handler, pickle.HIGHEST_PROTOCOL)
Exemplo n.º 2
0
def save_model(model: keras.models.Model, filepath: str) -> None:
    """Saves model to serialized file.

    Args:
        model: Keras model object.
        filepath: Filepath to which model is saved.

    Returns:
        None.
    """
    _logger.debug("Save model to {}".format(filepath))
    model.save(filepath, overwrite=True)
Exemplo n.º 3
0
def save_model(m: keras.models.Model, p: str = None, *args, **kwargs):
    if p is None:
        p = os.path.join(nb_dir, '.train_result')
    os.makedirs(p, exist_ok=True)
    window = kwargs.pop('window', None)
    days = kwargs.pop('days', None)
    stockcode = kwargs.pop('stockcode', None)
    if stockcode is None or window is None or days is None:
        raise ValueError()
    p = _get_model_file_path(stockcode, window, days, p)
    os.makedirs(os.path.dirname(p), exist_ok=True)
    m.save(p)
    return p
Exemplo n.º 4
0
def save_model(model: keras.models.Model, model_type: int):
    if model_type == ann_normalize.TYPE_FCN:
        model.save(fcn_norm_fix_model_path)
    elif model_type == ann_normalize.TYPE_CONV:
        model.save(conv_norm_fix_model_path)
    else:
        model.save(conv_bn_norm_fix_model_path)
Exemplo n.º 5
0
def save_normed_model(model: keras.models.Model, model_type: int):
    if model_type == TYPE_FCN:
        model.save(fcn_norm_model_path)
    elif model_type == TYPE_CONV:
        model.save(conv_norm_model_path)
    else:
        model.save(conv_bn_norm_model_path)
Exemplo n.º 6
0
 def save(self, path : str, model: keras.models.Model ):
     dump(self, os.path.join(path, f"solution_{self.id:03d}.pkl"))
     model.save(os.path.join(path, f"model_{self.id:03d}.h5"), include_optimizer=False)