code: def convert_flatten(
      builder,
      layer,
      input_names,
      output_names,
      keras_layer,
      respect_train,
  ):
      """
      Convert a flatten layer from keras to coreml.
      ----------
      Parameters
      keras_layer: layer
          A keras layer object.
  
      builder: NeuralNetworkBuilder
          A neural network builder object.
      respect_train: boolean
          Ignored.
      """
      input_name, output_name = (input_names[0], output_names[0])
  
      # blob_order == 0 if the input blob needs not be rearranged
      # blob_order == 1 if the input blob needs to be rearranged
      blob_order = 0
  
      # using keras_layer.input.shape have a "?" (Dimension[None] at the front),
      # making a 3D tensor with unknown batch size 4D
  
      try:
          in_shape = keras_layer.input_shape
          if len(in_shape) == 4:
              blob_order = 1
          if len(in_shape) == 3 and in_shape[0] is None:
              # handling Keras rank-3 tensor (Batch, Sequence, Channels)
              permute_output_name = output_name + "__permute__"
              builder.add_permute(
                  name=layer + "__permute__",
                  dim=(2, 1, 0, 3),
                  input_name=input_name,
                  output_name=permute_output_name,
              )
              builder.add_flatten(
                  name=layer,
                  mode=1,
                  input_name=permute_output_name,
                  output_name=output_name,
              )
          else:
              builder.add_flatten(
                  name=layer,
                  mode=blob_order,
                  input_name=input_name,
                  output_name=output_name,
              )
      except:
          builder.add_flatten(
              name=layer,
              mode=1,
              input_name=input_name,
              output_name=output_name,
          )
  
imports: from .None import _utils
  import logging
  import keras
  import numpy
  from ...proto import NeuralNetwork_pb2
  from distutils.version import StrictVersion
label_desc: Use image node_id 14 for calling a global function with example usage: convert_flatten(builder, layer, input_names, output_names, keras_layer, respect_train) without return types