class_docstr: Tests KerasLayer in an all-Keras environment.
class_docstr_tok: ["Tests","KerasLayer","in","an","all-Keras","environment","."]
code: def testRegularizationLoss(self, model_format):
      export_dir = os.path.join(self.get_temp_dir(), "half-plus-one")
      _dispatch_model_format(
          model_format, _save_half_plus_one_model, export_dir
      )
      # Import the half-plus-one model into a consumer model.
      inp = tf_keras_v2.layers.Input(shape=(1,), dtype=tf.float32)
      imported = hub.KerasLayer(export_dir, trainable=False)
      outp = imported(inp)
      model = tf_keras_v2.Model(inp, outp)
      # When untrainable, the layer does not contribute regularization losses.
      self.assertAllEqual(
          model.losses, np.array([0.0], dtype=np.float32)
      )
      # When trainable (even set after the fact), the layer forwards its losses.
      imported.trainable = True
      self.assertAllEqual(
          model.losses, np.array([0.0025], dtype=np.float32)
      )
      # This can be toggled repeatedly.
      imported.trainable = False
      self.assertAllEqual(
          model.losses, np.array([0.0], dtype=np.float32)
      )
      imported.trainable = True
      self.assertAllEqual(
          model.losses, np.array([0.0025], dtype=np.float32)
      )
  
imports: import json
  import os
  from absl.testing import parameterized
  import numpy
  import tensorflow
  import tensorflow_hub
label_desc: Use image node_id 2 for calling the KerasTest obj's underlying member method code with example usage: obj.testRegularizationLoss(model_format) without return types