code: def test_save_load(select_detector):
      det = select_detector
      det_name = det.meta["name"]
      with TemporaryDirectory() as temp_dir:
          temp_dir += "/"
          save_detector(det, temp_dir, legacy=True)
          det_load = load_detector(temp_dir)
          det_load_name = det_load.meta["name"]
          assert det_load_name == det_name
  
          if not type(det_load) in [
              OutlierProphet,
              ChiSquareDrift,
              ClassifierDrift,
              KSDrift,
              MMDDrift,
              TabularDrift,
          ]:
              assert det_load.threshold == det.threshold == threshold
  
          if type(det_load) in [OutlierVAE, OutlierVAEGMM]:
              assert det_load.samples == det.samples == samples
  
          if isinstance(det_load, (AdversarialAE, ModelDistillation)):
              for layer in det_load.model.layers:
                  assert not layer.trainable
  
          if isinstance(det_load, OutlierAEGMM):
              assert isinstance(
                  det_load.aegmm.encoder, tf.keras.Sequential
              )
              assert isinstance(
                  det_load.aegmm.decoder, tf.keras.Sequential
              )
              assert isinstance(
                  det_load.aegmm.gmm_density, tf.keras.Sequential
              )
              assert isinstance(det_load.aegmm, tf.keras.Model)
              assert det_load.aegmm.n_gmm == n_gmm
          elif isinstance(det_load, OutlierVAEGMM):
              assert isinstance(
                  det_load.vaegmm.encoder.encoder_net,
                  tf.keras.Sequential,
              )
              assert isinstance(
                  det_load.vaegmm.decoder, tf.keras.Sequential
              )
              assert isinstance(
                  det_load.vaegmm.gmm_density, tf.keras.Sequential
              )
              assert isinstance(det_load.vaegmm, tf.keras.Model)
              assert det_load.vaegmm.latent_dim == latent_dim
              assert det_load.vaegmm.n_gmm == n_gmm
          elif isinstance(det_load, (AdversarialAE, OutlierAE)):
              assert isinstance(
                  det_load.ae.encoder.encoder_net, tf.keras.Sequential
              )
              assert isinstance(
                  det_load.ae.decoder.decoder_net, tf.keras.Sequential
              )
              assert isinstance(det_load.ae, tf.keras.Model)
          elif isinstance(det_load, ModelDistillation):
              assert isinstance(
                  det_load.model, tf.keras.Sequential
              ) or isinstance(det_load.model, tf.keras.Model)
              assert isinstance(
                  det_load.distilled_model, tf.keras.Sequential
              ) or isinstance(det_load.distilled_model, tf.keras.Model)
          elif isinstance(det_load, OutlierVAE):
              assert isinstance(
                  det_load.vae.encoder.encoder_net, tf.keras.Sequential
              )
              assert isinstance(
                  det_load.vae.decoder.decoder_net, tf.keras.Sequential
              )
              assert isinstance(det_load.vae, tf.keras.Model)
              assert det_load.vae.latent_dim == latent_dim
          elif isinstance(det_load, Mahalanobis):
              assert det_load.clip is None
              assert det_load.mean == det_load.C == det_load.n == 0
              assert det_load.meta["detector_type"] == "outlier"
              assert det_load.meta["online"]
          elif isinstance(det_load, OutlierProphet):
              assert det_load.model.interval_width == 0.7
              assert det_load.model.growth == "logistic"
              assert det_load.meta["data_type"] == "time-series"
          elif isinstance(det_load, SpectralResidual):
              assert det_load.window_amp == 10
              assert det_load.window_local == 10
          elif isinstance(det_load, OutlierSeq2Seq):
              assert isinstance(det_load.seq2seq, tf.keras.Model)
              assert isinstance(
                  det_load.seq2seq.threshold_net, tf.keras.Sequential
              )
              assert isinstance(det_load.seq2seq.encoder, EncoderLSTM)
              assert isinstance(det_load.seq2seq.decoder, DecoderLSTM)
              assert det_load.latent_dim == latent_dim
              assert det_load.threshold == threshold
              assert det_load.shape == (-1, seq_len, input_dim)
          elif isinstance(det_load, KSDrift):
              assert det_load.n_features == latent_dim
              assert det_load.p_val == p_val
              assert (det_load.x_ref == X_ref).all()
              assert isinstance(det_load.preprocess_fn, Callable)
              assert (
                  det_load.preprocess_fn.func.__name__
                  == "preprocess_drift"
              )
          elif isinstance(det_load, (ChiSquareDrift, TabularDrift)):
              assert isinstance(det_load.x_ref_categories, dict)
              assert det_load.p_val == p_val
              x = (
                  X_ref_cat.copy()
                  if isinstance(det_load, ChiSquareDrift)
                  else X_ref_mix.copy()
              )
              assert (det_load.x_ref == x).all()
          elif isinstance(det_load, MMDDrift):
              assert not det_load._detector.infer_sigma
              assert det_load._detector.n_permutations == n_permutations
              assert det_load._detector.p_val == p_val
              assert (det_load._detector.x_ref == X_ref).all()
              assert isinstance(
                  det_load._detector.preprocess_fn, Callable
              )
              assert (
                  det_load._detector.preprocess_fn.func.__name__
                  == "preprocess_drift"
              )
          elif isinstance(det_load, ClassifierDrift):
              assert det_load._detector.p_val == p_val
              assert (det_load._detector.x_ref == X_ref).all()
              assert isinstance(det_load._detector.skf, StratifiedKFold)
              assert isinstance(det_load._detector.train_kwargs, dict)
              assert isinstance(
                  det_load._detector.model, tf.keras.Model
              )
          elif isinstance(det_load, LLR):
              assert isinstance(det_load.dist_s, tf.keras.Model)
              assert isinstance(det_load.dist_b, tf.keras.Model)
              assert not det_load.sequential
              assert not det_load.has_log_prob
  
file_path: alibi-detect/alibi_detect/utils/tests/test_saving_legacy.py
imports: from alibi_detect.utils.missing_optional_dependency import MissingDependency
  from functools import partial
  import numpy
  import pytest
  from sklearn.model_selection import StratifiedKFold
  from tempfile import TemporaryDirectory
  import tensorflow
  from tensorflow.keras.layers import Dense, InputLayer
  from typing import Callable
  from alibi_detect.ad import AdversarialAE, ModelDistillation
  from alibi_detect.cd import ChiSquareDrift, ClassifierDrift, KSDrift, MMDDrift, TabularDrift
  from alibi_detect.cd.tensorflow import UAE, preprocess_drift
  from alibi_detect.models.tensorflow.autoencoder import DecoderLSTM, EncoderLSTM
  from alibi_detect.od import IForest, LLR, Mahalanobis, OutlierAEGMM, OutlierVAE, OutlierVAEGMM, OutlierProphet, SpectralResidual, OutlierSeq2Seq, OutlierAE
  from alibi_detect.saving import save_detector, load_detector
label_desc: Use image node_id 2 for calling a global function with example usage: test_save_load(select_detector) without return types