コード例 #1
0
    def load(self, source: Union[str, Any], templatefile: str,
             key: str) -> None:  # type: ignore
        """
        Load a policy and associated templates under the given key

        If `source` is a string, it is taken as a path to a filename and the
        policy is loaded as an `LocalKerasModel` object.

        If `source` is not a string, it is taken as a custom object that
        implements the `__len__` and `predict` methods.

        :param source: the source of the policy model
        :param templatefile: the path to a HDF5 file with the templates
        :param key: the key or label
        :raises PolicyException: if the length of the model output vector is not same as the number of templates
        """
        self._logger.info(
            f"Loading expansion policy model from {source} to {key}")
        model = load_model(source, key, self._config.use_remote_models)

        self._logger.info(f"Loading templates from {templatefile} to {key}")
        templates: pd.DataFrame = pd.read_hdf(templatefile, "table")

        if hasattr(model, "output_size"
                   ) and len(templates) != model.output_size:  # type: ignore
            raise PolicyException(
                f"The number of templates ({len(templates)}) does not agree with the "  # type: ignore
                f"output dimensions of the model ({model.output_size})")

        self._items[key] = {"model": model, "templates": templates}
コード例 #2
0
 def __init__(self, key: str, config: Configuration, **kwargs: Any) -> None:
     super().__init__(key, config, **kwargs)
     source = kwargs["source"]
     self._logger.info(
         f"Loading filter policy model from {source} to {key}")
     self.model = load_model(source, key, self._config.use_remote_models)
     self._prod_fp_name = kwargs.get("prod_fp_name", "input_1")
     self._rxn_fp_name = kwargs.get("rxn_fp_name", "input_2")
コード例 #3
0
ファイル: policy.py プロジェクト: pk-organics/aizynthfinder
    def load(self, source: Union[str, Any], key: str) -> None:  # type: ignore
        """
        Load a policy under the given key

        If `source` is a string, it is taken as a path to a filename and the
        policy is loaded as an `LocalKerasModel` object.

        If `source` is not a string, it is taken as a custom object that
        implements the `__len__` and `predict` methods.

        :param source: the source of the policy model
        :param key: the key or label
        """
        self._logger.info(f"Loading filter policy model from {source} to {key}")
        self._items[key] = {
            "model": load_model(source, key, self._config.use_remote_models)
        }
コード例 #4
0
    def __init__(self, key: str, config: Configuration, **kwargs: str) -> None:
        super().__init__(key, config, **kwargs)

        source = kwargs["source"]
        templatefile = kwargs["templatefile"]

        self._logger.info(
            f"Loading template-based expansion policy model from {source} to {self.key}"
        )
        self.model = load_model(source, self.key,
                                self._config.use_remote_models)

        self._logger.info(
            f"Loading templates from {templatefile} to {self.key}")
        self.templates: pd.DataFrame = pd.read_hdf(templatefile, "table")

        if hasattr(self.model, "output_size") and len(
                self.templates) != self.model.output_size:  # type: ignore
            raise PolicyException(
                f"The number of templates ({len(self.templates)}) does not agree with the "  # type: ignore
                f"output dimensions of the model ({self.model.output_size})")