code: def convert_pooling(
      builder, layer, input_names, output_names, keras_layer
  ):
      """Convert pooling layer from keras to coreml.
  
      Parameters
      ----------
      keras_layer: layer
          A keras layer object.
  
      builder: NeuralNetworkBuilder
          A neural network builder object.
      """
      # Get input and output names
      input_name, output_name = (input_names[0], output_names[0])
  
      # Pooling layer type
      if (
          isinstance(
              keras_layer, keras.layers.convolutional.MaxPooling2D
          )
          or isinstance(
              keras_layer, keras.layers.convolutional.MaxPooling1D
          )
          or isinstance(
              keras_layer, keras.layers.pooling.GlobalMaxPooling2D
          )
          or isinstance(
              keras_layer, keras.layers.pooling.GlobalMaxPooling1D
          )
      ):
          layer_type_str = "MAX"
      elif (
          isinstance(
              keras_layer, keras.layers.convolutional.AveragePooling2D
          )
          or isinstance(
              keras_layer, keras.layers.convolutional.AveragePooling1D
          )
          or isinstance(
              keras_layer, keras.layers.pooling.GlobalAveragePooling2D
          )
          or isinstance(
              keras_layer, keras.layers.pooling.GlobalAveragePooling1D
          )
      ):
          layer_type_str = "AVERAGE"
      else:
          raise TypeError("Pooling type %s not supported" % keras_layer)
  
      # if it's global, set the global flag
      if isinstance(
          keras_layer, keras.layers.pooling.GlobalMaxPooling2D
      ) or isinstance(
          keras_layer, keras.layers.pooling.GlobalAveragePooling2D
      ):
          # 2D global pooling
          global_pooling = True
          height, width = (0, 0)
          stride_height, stride_width = (0, 0)
          padding_type = "VALID"
      elif isinstance(
          keras_layer, keras.layers.pooling.GlobalMaxPooling1D
      ) or isinstance(
          keras_layer, keras.layers.pooling.GlobalAveragePooling1D
      ):
          # 1D global pooling: 1D global pooling seems problematic,
          # use this work-around
          global_pooling = False
          _, width, channels = keras_layer.input_shape
          height = 1
          stride_height, stride_width = height, width
          padding_type = "VALID"
      else:
          global_pooling = False
          # Set pool sizes and strides
          # 1D cases:
          if (
              isinstance(
                  keras_layer, keras.layers.convolutional.MaxPooling1D
              )
              or isinstance(
                  keras_layer, keras.layers.pooling.GlobalMaxPooling1D
              )
              or isinstance(
                  keras_layer,
                  keras.layers.convolutional.AveragePooling1D,
              )
              or isinstance(
                  keras_layer,
                  keras.layers.pooling.GlobalAveragePooling1D,
              )
          ):
              height, width = 1, keras_layer.pool_length
              if keras_layer.stride is not None:
                  stride_height, stride_width = 1, keras_layer.stride
              else:
                  stride_height, stride_width = (
                      1,
                      keras_layer.pool_length,
                  )
          # 2D cases:
          else:
              height, width = keras_layer.pool_size
              if keras_layer.strides is None:
                  stride_height, stride_width = height, width
              else:
                  stride_height, stride_width = keras_layer.strides
  
          # Padding
          border_mode = keras_layer.border_mode
          if keras_layer.border_mode == "valid":
              padding_type = "VALID"
          elif keras_layer.border_mode == "same":
              padding_type = "SAME"
          else:
              raise TypeError(
                  "Border mode %s not supported" % border_mode
              )
  
      builder.add_pooling(
          name=layer,
          height=height,
          width=width,
          stride_height=stride_height,
          stride_width=stride_width,
          layer_type=layer_type_str,
          padding_type=padding_type,
          input_name=input_name,
          output_name=output_name,
          exclude_pad_area=True,
          is_global=global_pooling,
      )
  
imports: from .None import _utils
  import keras
  import numpy
label_desc: Use image node_id 8 for calling a global function with example usage: convert_pooling(builder, layer, input_names, output_names, keras_layer) without return types