Beispiel #1
0
def train(models, train_set, eval_set=None, silent=False):
    """Train all model for production and save them

    Args:
        models (list of str): Model names. Pass if you want to train a just a
            set particular models
        train_set (dg.enums.Dataset): Dataset to train on
        eval_set (dg.enums.Dataset): Dataset to use for evaluation during
            training.
        silent (bool): Don't print details to standard out.
    """
    config = Config()
    model_dir = config.get_model_dir()
    if not silent:
        print('Model dir: ', model_dir)

    bar(silent=silent)
    for model_id in models:
        model = config.models[model_id].set_params(
            **config.get_params(model_id))
        datasets = config.get_datasets(model.id)
        train_set = (datasets[train_set.value] if isinstance(
            train_set, Dataset) else train_set)
        eval_set = (datasets[eval_set.value]
                    if isinstance(eval_set, Dataset) else eval_set)
        train_model(model,
                    train_set=train_set,
                    eval_set=eval_set,
                    model_dir=model_dir,
                    save=True,
                    silent=silent)
        bar(silent=silent)
Beispiel #2
0
    def load(cls, model_dir):
        """Load the production model

        Args:
            model_dir (str): Path to the model dir from where we should load
                the model.
        """
        config = Config()
        with io.open(os.path.join(model_dir, 'params.yaml')) as f:
            params = yaml.safe_load(f)
        model = cls(**params)
        model.model_dir = config.get_model_dir(tensorflow=True)
        model.estimator = model._create_estimator(model_dir)
        return model