code: def _load_state_dict(
      detector: StateMixin, filepath: Path, raise_error: bool = True
  ):
      """
      Utility function to load a detector's state dictionary from a filepath, and update the detectors attributes with
      the values in the state dictionary.
  
      Parameters
      ----------
      detector
          The detector to update.
      filepath
          File to load state dictionary from.
      raise_error
          Whether to raise an error if a file is not found at `filepath`. Otherwise, raise a warning and skip loading.
  
      Returns
      -------
      None. The detector is updated inplace.
      """
      if filepath.is_file():
          if filepath.suffix == ".pt":
              state_dict = _load_state_dict_pt(filepath)
          else:
              state_dict = np.load(str(filepath))
          for key, value in state_dict.items():
              setattr(detector, key, value)
      else:
          if raise_error:
              raise FileNotFoundError(
                  "State file not found at {}.".format(filepath)
              )
          else:
              logger.warning(
                  "State file not found at {}. Skipping loading of state.".format(
                      filepath
                  )
              )
  
file_path: alibi-detect/alibi_detect/utils/state/state.py
imports: import os
  from pathlib import Path
  import logging
  from abc import ABC
  from typing import Union, Tuple
  import numpy
  from alibi_detect.utils.frameworks import Framework
  from alibi_detect.utils.state._pytorch import save_state_dict, load_state_dict
label_desc: Use image node_id 2 for calling a global function with example usage: _load_state_dict(detector, filepath, raise_error) without return types