code: def _add_metadata_to_ir(
      xml_file: str,
      metadata: dict[str, Any],
      input_size: tuple[int, int],
  ) -> None:
      """Adds the metadata to the model IR.
  
      Adds the metadata to the model IR. So that it can be used with the new modelAPI.
      This is because the metadata.json is not used by the new modelAPI.
      # TODO CVS-114640
      # TODO: Remove this function when Anomalib is upgraded as the model graph will contain the required ops
  
      Args:
          xml_file (str): Path to the xml file.
          metadata (dict[str, Any]): Metadata to add to the model.
          input_size (tuple[int, int]): Input size of the model.
      """
      core = Core()
      model = core.read_model(xml_file)
  
      _metadata = {}
      for key, value in metadata.items():
          if key in ("transform", "min", "max"):
              continue
          _metadata[("model_info", key)] = value
  
      # Add transforms
      if "transform" in metadata:
          for transform_dict in metadata["transform"]["transform"][
              "transforms"
          ]:
              transform = transform_dict["__class_fullname__"]
              if transform == "Normalize":
                  _metadata[
                      ("model_info", "mean_values")
                  ] = _serialize_list(
                      [x * 255.0 for x in transform_dict["mean"]]
                  )
                  _metadata[
                      ("model_info", "scale_values")
                  ] = _serialize_list(
                      [x * 255.0 for x in transform_dict["std"]]
                  )
              elif transform == "Resize":
                  _metadata[
                      ("model_info", "orig_height")
                  ] = transform_dict["height"]
                  _metadata[
                      ("model_info", "orig_width")
                  ] = transform_dict["width"]
              else:
                  warn(
                      f"Transform {transform} is not supported currently"
                  )
  
      # Since we only need the diff of max and min, we fuse the min and max into one op
      if "min" in metadata and "max" in metadata:
          _metadata[("model_info", "normalization_scale")] = (
              metadata["max"] - metadata["min"]
          )
  
      _metadata[("model_info", "reverse_input_channels")] = True
      _metadata[("model_info", "model_type")] = "AnomalyDetection"
      _metadata[("model_info", "labels")] = ["Normal", "Anomaly"]
      _metadata[("model_info", "image_shape")] = _serialize_list(
          input_size
      )
  
      for k, data in _metadata.items():
          model.set_rt_info(data, list(k))
  
      tmp_xml_path = Path(xml_file).parent / "tmp.xml"
      serialize(model, str(tmp_xml_path))
      # we delete the file if it already exists, to prevent WinError 183 error on Windows
      Path(xml_file).unlink(missing_ok=True)
      tmp_xml_path.rename(xml_file)
      # since we create new openvino IR files, we don't need the bin file. So we delete it.
      tmp_xml_path.with_suffix(".bin").unlink()
  
imports: from __future__ import annotations
  import json
  import logging
  import subprocess
  from enum import Enum
  from importlib.util import find_spec
  from pathlib import Path
  from typing import Any
  from warnings import warn
  import numpy
  import torch
  from torch import Tensor
  from torch.types import Number
  from anomalib.data.task_type import TaskType
  from anomalib.models.components import AnomalyModule
label_desc: Use image node_id 7 for calling a global function with example usage: _add_metadata_to_ir(xml_file, metadata, input_size) without return types