code: def _validate_image_input_output_shapes(
      color_layout, shape, name, is_input=True
  ):
      io_str = "input" if is_input else "output"
      if len(shape) != 4:
          raise ValueError(
              "Image {}, '{}', must have rank 4. Instead it has rank {}".format(
                  io_str, name, len(shape)
              )
          )
      if color_layout in (ColorLayout.BGR, ColorLayout.RGB):
          if shape[1] != 3 or shape[0] != 1:
              raise ValueError(
                  "Shape of the RGB/BGR image {}, '{}', must be of kind (1, 3, H, W), "
                  "i.e., first two dimensions must be (1, 3), instead they are: {}".format(
                      io_str, name, shape[:2]
                  )
              )
      elif color_layout in (
          ColorLayout.GRAYSCALE,
          ColorLayout.GRAYSCALE_FLOAT16,
      ):
          if shape[1] != 1 or shape[0] != 1:
              raise ValueError(
                  "Shape of the Grayscale image {}, '{}', must be of kind (1, 1, H, W), "
                  "i.e., first two dimensions must be (1, 1), instead they are: {}".format(
                      io_str, name, shape[:2]
                  )
              )
      else:
          raise KeyError(
              "Unrecognized color_layout {}".format(color_layout)
          )
  
imports: from coremltools.converters.mil.input_types import ColorLayout
  from coremltools.converters.mil.mil.passes.defs.preprocess import NameSanitizer
  from coremltools.proto import FeatureTypes_pb2
label_desc: Use image node_id 3 for calling a global function with example usage: _validate_image_input_output_shapes(color_layout, shape, name, is_input) without return types