code: def save_load_compare(
      layer,
      input_batch,
      allclose_func,
      save_format,
      layer_class=None,
      training=None,
      atol=1e-4,
  ):
      """test a model with `layer` with the given `input_batch`.
      The model prediction result is compared using `allclose_func` which may depend on the
      data type of the model output (e.g., float or complex).
      """
      model = tf.keras.models.Sequential()
      model.add(layer)
  
      result_ref = model(input_batch, training=training)
  
      os_temp_dir = tempfile.gettempdir()
      model_temp_dir = tempfile.TemporaryDirectory(dir=os_temp_dir)
  
      if save_format == "tf":
          model_path = model_temp_dir.name
      elif save_format == "h5":
          model_path = os.path.join(model_temp_dir.name, "model.h5")
      else:
          raise ValueError
      model.save(filepath=model_path, save_format=save_format)
      # if save_format == 'h5':
      #     import ipdb; ipdb.set_trace()
  
      if save_format == "h5":
          new_model = tf.keras.models.load_model(
              model_path,
              custom_objects={layer.__class__.__name__: layer_class},
          )
      else:
          new_model = tf.keras.models.load_model(model_path)
  
      result_new = new_model(input_batch)
      allclose_func(result_ref, result_new, atol)
  
      model_temp_dir.cleanup()
  
      return model
  
file_path: kapre/tests/utils.py
imports: import os
  from pathlib import Path
  import shutil
  import numpy
  import tensorflow
  import tempfile
  from tensorflow.keras import backend
label_desc: Use image node_id 3 for calling a global function with example usage: save_load_compare(layer, input_batch, allclose_func, save_format, layer_class, training, atol) and returns: model