docstr: Template for testing model saving and loading.
docstr_tok: ["Template","for","testing","model","saving","and","loading","."]
code: def _test_adv_model_save(self, model_fn):
      """Template for testing model saving and loading."""
      w, x0, y0, lr, adv_config, _ = self._set_up_linear_regression()
      model = model_fn(input_shape=(2,), weights=w)
      adv_model = adversarial_regularization.AdversarialRegularization(
          model, label_keys=["label"], adv_config=adv_config
      )
      adv_model.compile(
          optimizer=tf.keras.optimizers.SGD(lr), loss=["MAE"]
      )
  
      # Run the model before saving it. This is necessary for subclassed models.
      inputs = {"feature": x0, "label": y0}
      adv_model.evaluate(inputs, steps=1)
  
      saved_model_dir = os.path.join(self.get_temp_dir(), "saved_model")
      adv_model.save(saved_model_dir)
  
      loaded_model = tf.keras.models.load_model(saved_model_dir)
      self.assertEqual(
          len(loaded_model.trainable_weights),
          len(adv_model.trainable_weights),
      )
      for w_loaded, w_adv in zip(
          loaded_model.trainable_weights, adv_model.trainable_weights
      ):
          self.assertAllClose(
              tf.keras.backend.get_value(w_loaded),
              tf.keras.backend.get_value(w_adv),
          )
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import collections
  import os
  from absl.testing import parameterized
  import neural_structured_learning.configs
  from neural_structured_learning.keras import adversarial_regularization
  import numpy
  import tensorflow
  from tensorflow.python.framework import test_util
label_desc: Use image node_id 22 for calling the AdversarialRegularizationTest obj's underlying member method code with example usage: obj._test_adv_model_save(model_fn) without return types