def _tensor_to_type(
        self, output: Union[Tensor, List[Tensor]], output_type: str, is_batch: bool = False
    ) -> Union[Tensor, List[Tensor], List["Image.Image"]]:  # type: ignore
        """Convert the output tensor to the desired type.

        Args:
            output: The output tensor or list of tensors.
            output_type: The desired output type. Accepted values are "torch" and "pil".
            is_batch: If True, the output is expected to be a batch of tensors.

        Returns:
            The converted output tensor or list of tensors.

        Raises:
            RuntimeError: If the output type is not supported.

        """
        if output_type == "torch":
            if is_batch and not isinstance(output, Tensor):
                return stack(output)
            elif is_batch and isinstance(output, Tensor):
                return output
            elif not is_batch and isinstance(output, Tensor):
                return list(output)
            elif not is_batch and not isinstance(output, Tensor):
                return output
            return output
        elif output_type == "pil":
            out = [Image.fromarray((tensor_to_image(out_img) * 255).astype(np.uint8)) for out_img in output]  # type: ignore
            return list(out)

        raise RuntimeError(f"Unsupported output type `{output_type}`.")
Convert the output tensor to the desired type.

        Args:
            output: The output tensor or list of tensors.
            output_type: The desired output type. Accepted values are "torch" and "pil".
            is_batch: If True, the output is expected to be a batch of tensors.

        Returns:
            The converted output tensor or list of tensors.

        Raises:
            RuntimeError: If the output type is not supported.

        
kornia/models/base.py