Пример #1
0
    def unzip(self, experiment: ExperimentBackend) -> 'MetaBlock':
        """load fitting models from experiment.

        Raises:
            NotFittedError
                there is no `cv_dirs` in marked object.
                fit が呼ばれた段階で, MetaBlock class は cv_dirs に cv ごとのディレクトリを保存しています.
                これが参照できない場合 fit が呼ばれていないと判断して `NotFittedError` を送出します

        Args:
            experiment:
                読み込み対象の experiment

        Returns:
            myself
        """
        if not self._check_has_models_in_exp(experiment):
            raise NotFittedError(
                '`cv_dirs` is not found in marked object. Must be call fit before `unzip`.'
            )
        mark = experiment.get_marked()
        output_dirs = mark.get('cv_dirs', None)  # type: List[str]
        if output_dirs is None:
            raise NotFittedError(
                '`cv_dirs` is not found in marked object. Must be call fit before `unzip`.'
            )

        models = []
        for out_dir in output_dirs:
            with experiment.as_environment(out_dir,
                                           style='nested') as fold_env:
                model = fold_env.load_object('model')
            models.append(model)

        self._fitted_models = models
        return self
Пример #2
0
def test_can_call_method(backend: ExperimentBackend):
    backend.save_object('foo', {})
    backend.save_as_python_object('foo', {})

    assert not backend.can_save, backend.to
    assert backend.get_marked() is None
Пример #3
0
 def _check_has_models_in_exp(self, experiment: ExperimentBackend) -> bool:
     try:
         output_dirs = experiment.get_marked().get('cv_dirs', None)
     except (FileNotFoundError, AttributeError):
         return False
     return output_dirs is not None