コード例 #1
0
    def forward_as_dict(self,
                        tensors: Dict[str, tf.Tensor],
                        mode: str = None) -> Dict[str, tf.Tensor]:
        """Forward method on a dictionary of Tensors.

        The input ``tensors`` should contain all keys defined in
        ``self.inputs`` (but might contain more keys).
        It returns a new dictionary (does not mutate the input
        ``tensors`` dictionary in-place), whose keys are exactly
        ``self.outputs``.

        Parameters
        ----------
        tensors : Dict[str, tf.Tensor]
            Dictionary mapping self.inputs to tf.Tensors.
        mode : str, optional
            One of tf.estimator.ModeKeys

        Returns
        -------
        Dict[str, tf.Tensor]
            Dictionary mapping self.outputs to tf.Tensors
        """
        try:
            return item_to_dict(
                self.forward(dict_to_item(tensors, self.inputs), mode),
                self.outputs)
        except Exception as e:
            LOGGER.error(f"{self} error on {tensors}")
            raise e
コード例 #2
0
    def forward(self,
                tensors: Union[tf.Tensor, Tuple[tf.Tensor, ...]],
                mode: str = None) -> Union[tf.Tensor, Tuple[tf.Tensor, ...]]:
        """Forward method on one Tensor or a tuple of Tensors.

        Parameters
        ----------
        tensors : Union[tf.Tensor, Tuple[tf.Tensor, ...]]
            - n_in = 1: one tensor (NOT wrapped in a tuple)
            - n_in > 1: a tuple of tensors
        mode : str, optional
            Description

        Returns
        -------
        Union[tf.Tensor, Tuple[tf.Tensor, ...]]
            - n_out = 1: one tensor (NOT wrapped in a tuple)
            - n_out > 1: a tuple of tensors
        """
        try:
            return dict_to_item(
                self.forward_as_dict(item_to_dict(tensors, self.inputs), mode),
                self.outputs)
        except Exception as e:
            LOGGER.error(f"{self} error on {tensors}")
            raise e
コード例 #3
0
ファイル: base.py プロジェクト: Mbompr/deepr
 def forward_as_dict(self, tensors: Dict, mode: str = None) -> Dict:
     """Forward method of the layer on dictionaries of self.inputs"""
     try:
         return item_to_dict(
             self.forward(dict_to_item(tensors, self.inputs), mode),
             self.outputs)
     except Exception as e:
         LOGGER.error(f"{self} error on {tensors}")
         raise e
コード例 #4
0
ファイル: base.py プロジェクト: Mbompr/deepr
 def forward(self, tensors, mode: str = None):
     """Forward method of the layer on tuples"""
     try:
         return dict_to_item(
             self.forward_as_dict(item_to_dict(tensors, self.inputs), mode),
             self.outputs)
     except Exception as e:
         LOGGER.error(f"{self} error on {tensors}")
         raise e