code: def from_icevision_detection(record: "BaseRecord"):
      detection = record.detection
  
      result = {}
  
      if hasattr(detection, "bboxes"):
          result["bboxes"] = [
              {
                  "xmin": bbox.xmin,
                  "ymin": bbox.ymin,
                  "width": bbox.width,
                  "height": bbox.height,
              }
              for bbox in detection.bboxes
          ]
  
      masks = getattr(detection, "masks", None)
      mask_array = getattr(detection, "mask_array", None)
      if mask_array is not None or not _ICEVISION_GREATER_EQUAL_0_11_0:
          if (
              not isinstance(mask_array, MaskArray)
              or len(mask_array.data) == 0
          ):
              mask_array = MaskArray.from_masks(
                  masks, record.height, record.width
              )
  
          result["masks"] = [
              mask.data[0] for mask in _split_mask_array(mask_array)
          ]
      elif masks is not None:
          result[
              "masks"
          ] = masks  # Note - this doesn't unpack IceVision objects
  
      if hasattr(detection, "keypoints"):
          keypoints = detection.keypoints
  
          result["keypoints"] = []
          result["keypoints_metadata"] = []
  
          for keypoint in keypoints:
              keypoints_list = []
              for x, y, v in keypoint.xyv:
                  keypoints_list.append(
                      {
                          "x": x,
                          "y": y,
                          "visible": v,
                      }
                  )
              result["keypoints"].append(keypoints_list)
  
              # TODO: Unpack keypoints_metadata
              result["keypoints_metadata"].append(keypoint.metadata)
  
      if getattr(detection, "label_ids", None) is not None:
          result["labels"] = list(detection.label_ids)
  
      if getattr(detection, "scores", None) is not None:
          result["scores"] = list(detection.scores)
  
      return result
  
imports: from dataclasses import dataclass
  from typing import Any, Callable, Dict, List, Optional, Tuple
  import numpy
  from torch import Tensor, nn
  from flash.core.data.io.input import DataKeys
  from flash.core.data.io.input_transform import InputTransform
  from flash.core.utilities.imports import _ICEVISION_AVAILABLE, _ICEVISION_GREATER_EQUAL_0_11_0, _TOPIC_IMAGE_AVAILABLE, requires
label_desc: Use image node_id 3 for calling a global function with example usage: from_icevision_detection(record) and returns: result