code: def test_keras_custom_layer_model():
      # testing : https://coremltools.readme.io/docs/tensorflow-2#conversion-from-user-defined-models
  
      import tensorflow as tf
      from tensorflow import keras
      from tensorflow.keras import layers
  
      class CustomDense(layers.Layer):
          def __init__(self, units=32):
              super(CustomDense, self).__init__()
              self.units = units
  
          def build(self, input_shape):
              self.w = self.add_weight(
                  shape=(input_shape[-1], self.units),
                  initializer="random_normal",
                  trainable=True,
              )
              self.b = self.add_weight(
                  shape=(self.units,),
                  initializer="random_normal",
                  trainable=True,
              )
  
          def call(self, inputs):
              return tf.matmul(inputs, self.w) + self.b
  
      inputs = keras.Input((4,))
      outputs = CustomDense(10)(inputs)
      model = keras.Model(inputs, outputs)
      ct.convert(model)
  
imports: from os import getcwd, chdir
  from shutil import rmtree
  from os.path import exists
  from tempfile import mkdtemp
  import pytest
  import numpy
  import coremltools
  import os
  from coremltools._deps import _HAS_TF_1, _HAS_TF_2, _HAS_TORCH, MSG_TF1_NOT_FOUND, MSG_TF2_NOT_FOUND, MSG_TORCH_NOT_FOUND
label_desc: Use image node_id 7 for calling the TestTensorFlow2ConverterExamples obj's underlying member method code with example usage: obj.test_keras_custom_layer_model() and returns: unknown