def add_crop_resize(
        self,
        name,
        input_names,
        output_name,
        target_height=1,
        target_width=1,
        mode="STRICT_ALIGN_ENDPOINTS_MODE",
        normalized_roi=False,
        box_indices_mode="CORNERS_HEIGHT_FIRST",
        spatial_scale=1.0,
    ):
        """
        Add a crop resize layer to the model. A layer that extracts cropped spatial patches or RoIs (regions of interest)
        from the input and resizes them to a pre-specified size using bilinear interpolation.
        Note that RoI Align layer can be implemented with this layer followed by a pooling layer.
        Refer to the ``CropResizeLayerParams`` message in the specification (NeuralNetwork.proto) for more details.

        Parameters
        ----------

        name: str
            The name of this layer.

        input_names: list of str
            * Must be a list of two names: image feature map and crop indices/RoI input.
               * First input corresponds to a blob with shape ``[1, Batch, C, H_in, W_in]``.
                 This represents a batch of input image feature data with ``C`` channels.
               * The second input shape must be ``[N, 1, 4, 1, 1]`` or ``[N, 1, 5, 1, 1]``.
                 This represents the bounding box coordinates for ``N`` patches/RoIs.
            * ``N``: number of patches/RoIs to be extracted.
            * If RoI shape = ``[N, 1, 4, 1, 1]``, the channel axis corresponds
              to the four coordinates specifying the bounding box.
              All the N~ RoIs are extracted from all the batches of the input.
            * If RoI shape = ``[N, 1, 5, 1, 1]``, the first element of the
              channel axis specifies the input batch id from which to extract the RoI and
              must be in the interval ``[0, Batch - 1]``. That is, ``n`` -th RoI is
              extracted from the ``RoI[n,0,0,0]`` -th input batch id.
              The last four elements of the channel axis specify the
              bounding box coordinates.

        output_name: str
            The output blob name of this layer.

        target_height: int
            Output height dimension.

        target_width: int
            Output width dimension.

        mode: str
            * The following values are supported:
              ``'STRICT_ALIGN_ENDPOINTS_MODE'``, ``'ALIGN_ENDPOINTS_MODE'``,
              ``'UPSAMPLE_MODE'``, ``'ROI_ALIGN_MODE'``.
            * This parameter determines the sampling grid used for bilinear interpolation.

        normalized_roi: bool
            * If true the bounding box coordinates must be in the interval ``[0, 1]``.
              They are scaled by ``(input_height - 1)``, ``(input_width - 1)``;
              that is, based on the input spatial dimensions.
            * If false the bounding box coordinates must be in the interval
              ``[0, input_height - 1]`` and ``[0, input_width - 1]``,
              respectively for height and width dimensions.

        box_indices_mode: str
            * The following values are supported:
              ``'CORNERS_HEIGHT_FIRST'``, ``'CORNERS_WIDTH_FIRST'``,
              ``'CENTER_SIZE_HEIGHT_FIRST'``, ``'CENTER_SIZE_WIDTH_FIRST'``.
            * Representation used to interpret the bounding box coordinates (RoI) input.
                * ``'CORNERS_HEIGHT_FIRST'``: ``[h_start, w_start, h_end, w_end]``
                * ``'CORNERS_WIDTH_FIRST'``: ``[w_start, h_start, w_end, h_end]``
                * ``'CENTER_SIZE_HEIGHT_FIRST'``: ``[h_center, w_center, box_height, box_width]``
                * ``'CENTER_SIZE_WIDTH_FIRST'``: ``[w_center, h_center, box_width, box_height]``

        spatial_scale: float
            Additional spatial scale that multiplies the bounding box coordinates.
            Generally used while implementing the RoI Align layer,
            which uses unnormalized RoI coordinates along with a spatial scale less than or equal to 1.

        See Also
        --------
        add_resize_bilinear, add_crop
        """
        spec_layer = self._add_generic_layer(name, input_names, [output_name])
        spec_layer_params = spec_layer.cropResize
        spec_layer_params.targetSize.append(target_height)
        spec_layer_params.targetSize.append(target_width)
        spec_layer_params.normalizedCoordinates = normalized_roi
        spec_layer_params.spatialScale = spatial_scale

        mode = mode.upper() if isinstance(mode, str) else mode
        box_indices_mode = (
            box_indices_mode.upper()
            if isinstance(box_indices_mode, str)
            else box_indices_mode
        )

        if mode == "ALIGN_ENDPOINTS_MODE":
            spec_layer_params.mode.samplingMethod = (
                _proto.NeuralNetwork_pb2.SamplingMode.Method.Value("ALIGN_ENDPOINTS_MODE")
            )
        elif mode == "STRICT_ALIGN_ENDPOINTS_MODE":
            spec_layer_params.mode.samplingMethod = (
                _proto.NeuralNetwork_pb2.SamplingMode.Method.Value("STRICT_ALIGN_ENDPOINTS_MODE")
            )
        elif mode == "UPSAMPLE_MODE":
            spec_layer_params.mode.samplingMethod = (
                _proto.NeuralNetwork_pb2.SamplingMode.Method.Value("UPSAMPLE_MODE")
            )
        elif mode == "ROI_ALIGN_MODE":
            spec_layer_params.mode.samplingMethod = (
                _proto.NeuralNetwork_pb2.SamplingMode.Method.Value("ROI_ALIGN_MODE")
            )
        else:
            raise ValueError("Unsupported crop resize mode %s" % mode)

        if box_indices_mode == "CORNERS_HEIGHT_FIRST":
            spec_layer_params.boxIndicesMode.boxMode = (
                _proto.NeuralNetwork_pb2.BoxCoordinatesMode.Coordinates.Value(
                    "CORNERS_HEIGHT_FIRST"
                )
            )
        elif box_indices_mode == "CORNERS_WIDTH_FIRST":
            spec_layer_params.boxIndicesMode.boxMode = (
                _proto.NeuralNetwork_pb2.BoxCoordinatesMode.Coordinates.Value("CORNERS_WIDTH_FIRST")
            )
        elif box_indices_mode == "CENTER_SIZE_HEIGHT_FIRST":
            spec_layer_params.boxIndicesMode.boxMode = (
                _proto.NeuralNetwork_pb2.BoxCoordinatesMode.Coordinates.Value(
                    "CENTER_SIZE_HEIGHT_FIRST"
                )
            )
        elif box_indices_mode == "CENTER_SIZE_WIDTH_FIRST":
            spec_layer_params.boxIndicesMode.boxMode = (
                _proto.NeuralNetwork_pb2.BoxCoordinatesMode.Coordinates.Value(
                    "CENTER_SIZE_WIDTH_FIRST"
                )
            )
        else:
            raise ValueError(
                "Unsupported crop resize box indices mode %s" % box_indices_mode
            )
        return spec_layer

        Add a crop resize layer to the model. A layer that extracts cropped spatial patches or RoIs (regions of interest)
        from the input and resizes them to a pre-specified size using bilinear interpolation.
        Note that RoI Align layer can be implemented with this layer followed by a pooling layer.
        Refer to the ``CropResizeLayerParams`` message in the specification (NeuralNetwork.proto) for more details.

        Parameters
        ----------

        name: str
            The name of this layer.

        input_names: list of str
            * Must be a list of two names: image feature map and crop indices/RoI input.
               * First input corresponds to a blob with shape ``[1, Batch, C, H_in, W_in]``.
                 This represents a batch of input image feature data with ``C`` channels.
               * The second input shape must be ``[N, 1, 4, 1, 1]`` or ``[N, 1, 5, 1, 1]``.
                 This represents the bounding box coordinates for ``N`` patches/RoIs.
            * ``N``: number of patches/RoIs to be extracted.
            * If RoI shape = ``[N, 1, 4, 1, 1]``, the channel axis corresponds
              to the four coordinates specifying the bounding box.
              All the N~ RoIs are extracted from all the batches of the input.
            * If RoI shape = ``[N, 1, 5, 1, 1]``, the first element of the
              channel axis specifies the input batch id from which to extract the RoI and
              must be in the interval ``[0, Batch - 1]``. That is, ``n`` -th RoI is
              extracted from the ``RoI[n,0,0,0]`` -th input batch id.
              The last four elements of the channel axis specify the
              bounding box coordinates.

        output_name: str
            The output blob name of this layer.

        target_height: int
            Output height dimension.

        target_width: int
            Output width dimension.

        mode: str
            * The following values are supported:
              ``'STRICT_ALIGN_ENDPOINTS_MODE'``, ``'ALIGN_ENDPOINTS_MODE'``,
              ``'UPSAMPLE_MODE'``, ``'ROI_ALIGN_MODE'``.
            * This parameter determines the sampling grid used for bilinear interpolation.

        normalized_roi: bool
            * If true the bounding box coordinates must be in the interval ``[0, 1]``.
              They are scaled by ``(input_height - 1)``, ``(input_width - 1)``;
              that is, based on the input spatial dimensions.
            * If false the bounding box coordinates must be in the interval
              ``[0, input_height - 1]`` and ``[0, input_width - 1]``,
              respectively for height and width dimensions.

        box_indices_mode: str
            * The following values are supported:
              ``'CORNERS_HEIGHT_FIRST'``, ``'CORNERS_WIDTH_FIRST'``,
              ``'CENTER_SIZE_HEIGHT_FIRST'``, ``'CENTER_SIZE_WIDTH_FIRST'``.
            * Representation used to interpret the bounding box coordinates (RoI) input.
                * ``'CORNERS_HEIGHT_FIRST'``: ``[h_start, w_start, h_end, w_end]``
                * ``'CORNERS_WIDTH_FIRST'``: ``[w_start, h_start, w_end, h_end]``
                * ``'CENTER_SIZE_HEIGHT_FIRST'``: ``[h_center, w_center, box_height, box_width]``
                * ``'CENTER_SIZE_WIDTH_FIRST'``: ``[w_center, h_center, box_width, box_height]``

        spatial_scale: float
            Additional spatial scale that multiplies the bounding box coordinates.
            Generally used while implementing the RoI Align layer,
            which uses unnormalized RoI coordinates along with a spatial scale less than or equal to 1.

        See Also
        --------
        add_resize_bilinear, add_crop
        
coremltools/models/neural_network/builder.py