示例#1
0
    def batch_handler(self,
                      *,
                      dct: Dict,
                      model: nn.Module,
                      state: RunnerState = None) -> Dict:
        """
        Batch handler wrapper with main statistics and device management.

        :param dct: key-value storage with input tensors
        :param model: model to predict with
        :param state: runner state
        :return: key-value storage with model predictions
        """
        dct = {key: value.to(self.device) for key, value in dct.items()}
        if state is not None:
            state.input = dct
        output = self._batch_handler(dct=dct, model=model)
        return output
示例#2
0
    def batch_handler(self,
                      *,
                      dct: Dict,
                      model: nn.Module,
                      state: RunnerState = None) -> Dict:
        """
        Batch handler wrapper with main statistics and device management.

        :param dct: key-value storage with input tensors
        :param model: model to predict with
        :param state: runner state
        :return: key-value storage with model predictions
        """
        if isinstance(dct, (tuple, list)):
            assert len(dct) == 2
            dct = {"features": dct[0], "targets": dct[1]}
        dct = {key: value.to(state.device) for key, value in dct.items()}
        if state is not None:
            state.input = dct
        logits = model(dct["features"])
        output = {"logits": logits}
        return output