code: def _save_half_plus_one_model(export_dir, save_from_keras=False):
      """Writes Hub-style SavedModel to compute y = wx + 1, with w trainable."""
      inp = tf_keras_v2.layers.Input(shape=(1,), dtype=tf.float32)
      times_w = tf_keras_v2.layers.Dense(
          units=1,
          kernel_initializer=tf_keras_v2.initializers.Constant([[0.5]]),
          kernel_regularizer=tf_keras_v2.regularizers.l2(0.01),
          use_bias=False,
      )
      plus_1 = tf_keras_v2.layers.Dense(
          units=1,
          kernel_initializer=tf_keras_v2.initializers.Constant([[1.0]]),
          bias_initializer=tf_keras_v2.initializers.Constant([1.0]),
          trainable=False,
      )
      outp = plus_1(times_w(inp))
      model = tf_keras_v2.Model(inp, outp)
  
      if save_from_keras:
          tf.saved_model.save(model, export_dir)
          return
  
      @tf.function(
          input_signature=[
              tf.TensorSpec(shape=(None, 1), dtype=tf.float32)
          ]
      )
      def call_fn(inputs):
          return model(inputs, training=False)
  
      obj = tf.train.Checkpoint()
      obj.__call__ = call_fn
      obj.variables = (
          model.trainable_variables + model.non_trainable_variables
      )
      assert len(obj.variables) == 3, "Expect 2 kernels and 1 bias."
      obj.trainable_variables = [times_w.kernel]
      assert len(model.losses) == 1, "Expect 1 regularization loss."
      obj.regularization_losses = [
          tf.function(lambda: model.losses[0], input_signature=[])
      ]
      tf.saved_model.save(obj, export_dir)
  
imports: import json
  import os
  from absl.testing import parameterized
  import numpy
  import tensorflow
  import tensorflow_hub
label_desc: Use image node_id 3 for calling a global function with example usage: _save_half_plus_one_model(export_dir, save_from_keras) and returns: model