code: def from_icevision_record(record: "BaseRecord"):
      sample = {
          DataKeys.METADATA: {
              "size": getattr(
                  record, "original_size", (record.height, record.width)
              ),
              "output_size": (record.height, record.width),
          }
      }
  
      if getattr(record, "record_id", None) is not None:
          sample[DataKeys.METADATA]["image_id"] = record.record_id
  
      if getattr(record, "filepath", None) is not None:
          sample[DataKeys.METADATA]["filepath"] = record.filepath
  
      if record.img is not None:
          sample[DataKeys.INPUT] = record.img
          filepath = getattr(record, "filepath", None)
          if filepath is not None:
              sample[DataKeys.METADATA]["filepath"] = filepath
      elif getattr(record, "filepath", None) is not None:
          sample[DataKeys.INPUT] = record.filepath
  
      sample[DataKeys.TARGET] = from_icevision_detection(record)
  
      if getattr(record.detection, "class_map", None) is not None:
          sample[DataKeys.METADATA][
              "class_map"
          ] = record.detection.class_map
  
      return sample
  
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 4 for calling a global function with example usage: from_icevision_record(record) and returns: sample