code: def layer_counts(spec, layer_type):
      spec_type_map = {
          "neuralNetworkClassifier": spec.neuralNetworkClassifier,
          "neuralNetwork": spec.neuralNetwork,
          "neuralNetworkRegressor": spec.neuralNetworkRegressor,
      }
      nn_spec = spec_type_map.get(spec.WhichOneof("Type"))
      if nn_spec is None:
          raise ValueError("MLModel must have a neural network")
  
      n = 0
      for layer in nn_spec.layers:
          if layer.WhichOneof("layer") == layer_type:
              n += 1
      return n
  
imports: import os
  import tempfile
  import numpy
  import pytest
  import coremltools.models.utils
  from coremltools._deps import _HAS_TF_2
  from coremltools.converters.mil.testing_reqs import ct
  from coremltools.converters.mil.testing_utils import compare_backend, ct_convert, validate_minimum_deployment_target
  from tensorflow.python.framework import dtypes
  from tensorflow.python.keras.saving import saving_utils
  from tensorflow.python.tools.freeze_graph import freeze_graph
label_desc: Use image node_id 7 for calling a global function with example usage: layer_counts(spec, layer_type) and returns: n