code: def subclassing_api_model(num_classes):
      class SubclassedModel(tf.keras.models.Model):
          def __init__(self, name="subclassed"):
              super(SubclassedModel, self).__init__(name=name)
              self.conv_1 = tf.keras.layers.Conv2D(
                  filters=32, kernel_size=(3, 3), activation="relu"
              )
              self.conv_2 = tf.keras.layers.Conv2D(
                  filters=64, kernel_size=(3, 3), activation="relu"
              )
              self.maxpool_1 = tf.keras.layers.MaxPool2D(
                  pool_size=(2, 2)
              )
  
              self.conv_3 = tf.keras.layers.Conv2D(
                  filters=32, kernel_size=(3, 3), activation="relu"
              )
              self.conv_4 = tf.keras.layers.Conv2D(
                  filters=64,
                  kernel_size=(3, 3),
                  activation="relu",
                  name="grad_cam_target",
              )
              self.maxpool_2 = tf.keras.layers.MaxPool2D(
                  pool_size=(2, 2)
              )
  
              self.flatten = tf.keras.layers.Flatten()
  
              self.dense_1 = tf.keras.layers.Dense(
                  64, activation="relu"
              )
  
              self.dense_2 = tf.keras.layers.Dense(
                  num_classes, activation="softmax"
              )
  
          def build(self, input_shape):
              super(SubclassedModel, self).build(input_shape)
  
          def call(self, inputs, **kwargs):
              x = inputs
              for layer in [
                  self.conv_1,
                  self.conv_2,
                  self.maxpool_1,
                  self.conv_3,
                  self.conv_4,
                  self.maxpool_2,
                  self.flatten,
                  self.dense_1,
                  self.dense_2,
              ]:
                  x = layer(x)
  
              return x
  
          def compute_output_shape(self, input_shape):
              shape = tf.TensorShape(input_shape).as_list()
              return tf.TensorShape([shape[0], num_classes])
  
      model = SubclassedModel()
  
      model(
          np.random.random([4, *INPUT_SHAPE]).astype("float32")
      )  # Sample call to build the model
  
      model.compile(
          optimizer="adam",
          loss="categorical_crossentropy",
          metrics=["accuracy"],
      )
  
      return model
  
file_path: tf-explain/tests/integration/test_keras_api.py
imports: import numpy
  import pytest
  import tensorflow
  import tf_explain
label_desc: Use image node_id 3 for calling a global function with example usage: subclassing_api_model(num_classes) and returns: model, x, tf