class_docstr: Basic Inference Task Helper
class_docstr_tok: ["Basic","Inference","Task","Helper"]
docstr: You can provide your own writer.  However, this writer saves the prediction/label mask to file
  and fetches result json
  
  :param data: typically it is post processed data
  :param extension: output label extension
  :param dtype: output label dtype
  :return: tuple of output_file and result_json
code: def writer(
      self, data: Dict[str, Any], extension=None, dtype=None
  ) -> Tuple[Any, Any]:
      """
      You can provide your own writer.  However, this writer saves the prediction/label mask to file
      and fetches result json
  
      :param data: typically it is post processed data
      :param extension: output label extension
      :param dtype: output label dtype
      :return: tuple of output_file and result_json
      """
      logger.info("Writing Result...")
      if extension is not None:
          data["result_extension"] = extension
      if dtype is not None:
          data["result_dtype"] = dtype
      if self.labels is not None:
          data["labels"] = self.labels
  
      if self.type == InferType.CLASSIFICATION:
          if isinstance(self.labels, dict):
              label_names = {v: k for k, v in self.labels.items()}
          else:
              label_names = (
                  {v: k for v, k in enumerate(self.labels)}
                  if isinstance(self.labels, Sequence)
                  else None
              )
  
          cw = ClassificationWriter(
              label=self.output_label_key, label_names=label_names
          )
          return cw(data)
  
      if self.type == InferType.DETECTION:
          dw = DetectionWriter()
          return dw(data)
  
      writer = Writer(
          label=self.output_label_key, json=self.output_json_key
      )
      return writer(data)
  
imports: import copy
  import logging
  import os
  import time
  from abc import abstractmethod
  from enum import Enum
  from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union
  import torch
  from monai.data import decollate_batch
  from monai.inferers import Inferer, SimpleInferer, SlidingWindowInferer
  from monai.utils import deprecated
  from monailabel.interfaces.exception import MONAILabelError, MONAILabelException
  from monailabel.interfaces.tasks.infer_v2 import InferTask, InferType
  from monailabel.interfaces.utils.transform import dump_data, run_transforms
  from monailabel.transform.cache import CacheTransformDatad
  from monailabel.transform.writer import ClassificationWriter, DetectionWriter, Writer
  from monailabel.utils.others.generic import device_list, device_map, name_to_device
label_desc: Use image node_id 20 for calling the BasicInferTask obj's underlying member method code with example usage: obj.writer(data, extension, dtype) and returns: writer, cw, dw