docstr: Template for testing model saving and loading.
docstr_tok: ["Template","for","testing","model","saving","and","loading","."]
code: def _test_graph_reg_model_save(self, model_fn):
      """Template for testing model saving and loading."""
      w = np.array([[4.0], [-3.0]])
      base_model = model_fn((2,), w)
      graph_reg_config = configs.make_graph_reg_config(
          max_neighbors=1, multiplier=1
      )
      graph_reg_model = graph_regularization.GraphRegularization(
          base_model, graph_reg_config
      )
      graph_reg_model.compile(
          optimizer=tf.keras.optimizers.SGD(LEARNING_RATE),
          loss="MSE",
          metrics=["accuracy"],
      )
  
      # Run the model before saving it. This is necessary for subclassed models.
      inputs = {FEATURE_NAME: tf.constant([[5.0, 3.0]])}
      graph_reg_model.predict(inputs, steps=1, batch_size=1)
      saved_model_dir = os.path.join(self.get_temp_dir(), "saved_model")
      graph_reg_model.save(saved_model_dir)
  
      loaded_model = tf.keras.models.load_model(saved_model_dir)
      self.assertEqual(
          len(loaded_model.trainable_weights),
          len(graph_reg_model.trainable_weights),
      )
      for w_loaded, w_graph_reg in zip(
          loaded_model.trainable_weights,
          graph_reg_model.trainable_weights,
      ):
          self.assertAllClose(
              tf.keras.backend.get_value(w_loaded),
              tf.keras.backend.get_value(w_graph_reg),
          )
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import os
  from absl.testing import parameterized
  from neural_structured_learning import configs
  from neural_structured_learning.keras import graph_regularization
  import numpy
  import tensorflow
  from google.protobuf import text_format
  from tensorflow.python.framework import test_util
label_desc: Use image node_id 10 for calling the GraphRegularizationTest obj's underlying member method code with example usage: obj._test_graph_reg_model_save(model_fn) without return types