code: def maybe_handshake_model(keras_model):
      """Call the required predict/compile/build APIs to initialize a model if it
      is a subclass of tf.keras.Model. This is required to be able to call set_weights
      on subclassed layers."""
      try:
          keras_model.get_config()
          return keras_model
      except (AttributeError, NotImplementedError):
          # Subclassed models don't implement get_config
          pass
  
      for prop_name in ["catalogue_name", "eg_x", "eg_y", "eg_shape"]:
          if not hasattr(keras_model, prop_name):
              raise ValueError(
                  "Keras subclassed models are not whole-model serializable by "
                  "TensorFlow. To work around this, you must decorate your keras "
                  "model subclasses with the 'keras_subclass' decorator. The decorator "
                  "requires a single X/Y input of fake-data that can be used to initialize "
                  "your subclass model properly when loading the saved version."
              )
  
      ops: Ops = get_current_ops()
      if ops.device_type == "cpu":
          device = "CPU"
      else:  # pragma: no cover
          device = tf.test.gpu_device_name()
  
      compile_args = keras_model.eg_compile
  
      with tf.device(device):
          # Calling predict creates layers and weights for subclassed models
          keras_model.compile(**compile_args)
          keras_model.build(keras_model.eg_shape)
          keras_model.predict(keras_model.eg_x)
          # Made public in 2.2.x
          if hasattr(keras_model, "_make_train_function"):
              keras_model._make_train_function()
          else:
              keras_model.make_train_function()
      return keras_model
  
imports: import contextlib
  import copy
  from io import BytesIO
  from typing import Any, Dict, List, Optional
  import catalogue
  import numpy
  from ..backends import Ops, get_current_ops
  from ..compat import cupy, h5py
  from ..compat import tensorflow
  from ..optimizers import Optimizer
  from ..types import ArgsKwargs, ArrayXd
  from ..util import get_array_module
  from .shim import Shim
label_desc: Use image node_id 1 for calling a global function with example usage: maybe_handshake_model(keras_model) and returns: keras_model, keras_model