code: def fetch_detector(
      filepath: Union[str, os.PathLike],
      detector_type: str,
      dataset: str,
      detector_name: str,
      model: str = None,
  ) -> Data:
      """
      Fetch an outlier or adversarial detector from a google bucket, save it locally and return
      the initialised detector.
  
      Parameters
      ----------
      filepath
          Local directory to save detector to.
      detector_type
          `outlier` or `adversarial`.
      dataset
          Dataset of pre-trained detector. E.g. `kddcup`, `cifar10` or `ecg`.
      detector_name
          Name of the detector in the bucket.
      model
          Classification model used for adversarial detection.
  
      Returns
      -------
      Initialised pre-trained detector.
      """
      # create path (if needed)
      filepath = Path(filepath)
      if not filepath.is_dir():
          filepath.mkdir(parents=True, exist_ok=True)
          logger.warning(
              "Directory {} does not exist and is now created.".format(
                  filepath
              )
          )
      # create url of detector
      url = "https://storage.googleapis.com/seldon-models/alibi-detect/"
      if detector_type == "adversarial":
          url = _join_url(url, ["ad", dataset, model, detector_name])
      elif detector_type == "outlier":
          url = _join_url(url, ["od", detector_name, dataset])
  
      # fetch the metadata and state dict
      meta, state_dict = fetch_state_dict(
          url, filepath, save_state_dict=True
      )
  
      # load detector
      name = meta["name"]
      kwargs: dict = {}
      if name == "OutlierAE":
          fetch_ae(url, filepath)
      elif name == "OutlierAEGMM":
          fetch_aegmm(url, filepath)
      elif name == "OutlierVAE":
          fetch_vae(url, filepath)
      elif name == "OutlierVAEGMM":
          fetch_vaegmm(url, filepath)
      elif name == "OutlierSeq2Seq":
          fetch_seq2seq(url, filepath)
      elif name == "AdversarialAE":
          fetch_ad_ae(url, filepath, state_dict)
          if model == "resnet56":
              kwargs = {"custom_objects": {"backend": backend}}
      elif name == "ModelDistillation":
          fetch_ad_md(url, filepath)
          if model == "resnet56":
              kwargs = {"custom_objects": {"backend": backend}}
      elif name == "LLR":
          model_type = fetch_llr(url, filepath)
          if model_type == "weights":
              kwargs = get_pixelcnn_default_kwargs()
      detector = load_detector(filepath, **kwargs)
      return detector
  
imports: import logging
  import os
  from io import BytesIO
  from pathlib import Path
  from typing import Union, TYPE_CHECKING, Tuple
  import dill
  import requests
  from requests import RequestException
  import tensorflow
  from tensorflow.python.keras import backend
  from alibi_detect.models.tensorflow import PixelCNN
  from alibi_detect.saving import load_detector
  from alibi_detect.utils.url import _join_url
label_desc: Use image node_id 13 for calling a global function with example usage: fetch_detector(filepath, detector_type, dataset, detector_name, model) and returns: detector