code: def convert_raw_prediction(
      sample,
      raw_pred: dict,
      record: Sequence[BaseRecord],
      detection_threshold: float,
      mask_threshold: float,
      keep_image: bool = False,
  ):
      pred = faster_convert_raw_prediction(
          sample=sample,
          raw_pred=raw_pred,
          record=record,
          detection_threshold=detection_threshold,
          keep_image=keep_image,
      )
  
      above_threshold = pred.detection.above_threshold
      masks_probs = raw_pred["masks"][above_threshold]
      masks_probs = masks_probs.detach().cpu().numpy()
      # convert probabilities to 0 or 1 based on mask_threshold
      masks = masks_probs > mask_threshold
      masks = MaskArray(masks.squeeze(1))
  
      pred.pred.add_component(InstanceMasksRecordComponent())
      pred.detection.set_mask_array(masks)
  
      if keep_image:
          # HACK: quick fix for when we have to add masks back
          if len(sample) > 1:
              tensor_image, label = sample
              mask = MaskArray(np.array(label["masks"].cpu().numpy()))
              pred.ground_truth.detection.set_mask_array(mask)
  
      return pred
  
file_path: icevision/icevision/models/torchvision/mask_rcnn/prediction.py
imports: from icevision.imports import *
  from icevision.utils import *
  from icevision.core import *
  from icevision.data import *
  from icevision.models.utils import _predict_from_dl
  from icevision.models.torchvision.mask_rcnn.dataloaders import *
  from icevision.models.torchvision.faster_rcnn.prediction import convert_raw_prediction
label_desc: Use image node_id 5 for calling a global function with example usage: convert_raw_prediction(sample, raw_pred, record, detection_threshold, mask_threshold, keep_image) and returns: pred