Document feedback

Question document fragment

When a question document fragment contains a formula, it is displayed as a space.

Submission type
issue

It's a little complicated...

I'd like to ask someone.

Please select the submission type

Problem type
Specifications and Common Mistakes

- Specifications and Common Mistakes:

- Misspellings or punctuation mistakes,incorrect formulas, abnormal display.

- Incorrect links, empty cells, or wrong formats.

- Chinese characters in English context.

- Minor inconsistencies between the UI and descriptions.

- Low writing fluency that does not affect understanding.

- Incorrect version numbers, including software package names and version numbers on the UI.

Usability

- Usability:

- Incorrect or missing key steps.

- Missing main function descriptions, keyword explanation, necessary prerequisites, or precautions.

- Ambiguous descriptions, unclear reference, or contradictory context.

- Unclear logic, such as missing classifications, items, and steps.

Correctness

- Correctness:

- Technical principles, function descriptions, supported platforms, parameter types, or exceptions inconsistent with that of software implementation.

- Incorrect schematic or architecture diagrams.

- Incorrect commands or command parameters.

- Incorrect code.

- Commands inconsistent with the functions.

- Wrong screenshots.

- Sample code running error, or running results inconsistent with the expectation.

Risk Warnings

- Risk Warnings:

- Lack of risk warnings for operations that may damage the system or important data.

Content Compliance

- Content Compliance:

- Contents that may violate applicable laws and regulations or geo-cultural context-sensitive words and expressions.

- Copyright infringement.

Please select the type of question

Problem description

Describe the bug so that we can quickly locate the problem.

mindspore.ops.crop_and_resize

mindspore.ops.crop_and_resize(image, boxes, box_indices, crop_size, method='bilinear', extrapolation_value=0.0)[source]

Extracts crops from the input image Tensor and resizes them.

Note

In case that the output shape depends on crop_size, the crop_size must be constant. For now, the backward of the operator only support bilinear method, for other methods, will return 0.

Parameters
  • image (Tensor) – A 4-D Tensor representing a batch of images. It has shape (batch,image_height,image_width,depth).

  • boxes (Tensor) – A 2-D Tensor with shape (num_boxes,4) representing the normalized coordinates of the boxes to be cropped. The coordinates are specified in the form [y1,x1,y2,x2], where (y1,x1) is the first corner and (y2,x2) is the second corner of the box. If y1>y2, the sampled crop is inverted upside down, the width dimensionis treated similarly when x1>x2. If normalized coordinates are not in range [0,1], extrapolated input image values are used instead. Supported data type: float32.

  • box_indices (Tensor) – A 1-D Tensor of shape (num_boxes) representing the batch index for each box. Supported type: int32.

  • crop_size (Tuple[int]) – A tuple of two elements: (crop_height, crop_width), representing the output size of the cropped and resized images. Only positive values are supported. Supported type: int32.

  • method (str, optional) – An optional string that specifies the sampling method for resizing. It can be “bilinear”, “nearest” or “bilinear_v2”. The option “bilinear” stands for standard bilinear interpolation algorithm, while “bilinear_v2” may result in better result in some cases. “nearest” is the nearest neighbor interpolation algorithm. Default: “bilinear”.

  • extrapolation_value (float, optional) – An optional float value used extrapolation, if applicable. Default: 0.0.

Returns

A 4-D tensor of shape (numboxes,cropheight,cropwidth,depth) with type(float32).

Raises
  • TypeError – If image or boxes or box_indices is not a Tensor.

  • TypeError – If crop_size is not a Tuple with two int32 elements.

  • TypeError – If dtype of boxes is not float or that of box_indices is not int.

  • TypeError – If method is not a str.

  • TypeError – If extrapolation_value is not a float.

  • ValueError – If the shape rank of image is not 4.

  • ValueError – If the shape rank of boxes is not 2.

  • ValueError – If the second dim of boxes is not 4.

  • ValueError – If the shape rank of box_indices is not 1.

  • ValueError – If the first dim of box_indices is not equal to that of boxes.

  • ValueError – If existing element in box_indices is out of range [0, batch).

  • ValueError – If the data of crop_size is not positive.

  • ValueError – If method is not one of ‘bilinear’, ‘nearest’, ‘bilinear_v2’.

Supported Platforms:

Ascend GPU CPU

Examples

>>> BATCH_SIZE = 1
>>> NUM_BOXES = 5
>>> IMAGE_HEIGHT = 256
>>> IMAGE_WIDTH = 256
>>> CHANNELS = 3
>>> image = np.random.normal(size=[BATCH_SIZE, IMAGE_HEIGHT, IMAGE_WIDTH, CHANNELS]).astype(np.float32)
>>> boxes = np.random.uniform(size=[NUM_BOXES, 4]).astype(np.float32)
>>> box_indices = np.random.uniform(size=[NUM_BOXES], low=0, high=BATCH_SIZE).astype(np.int32)
>>> crop_size = (24, 24)
>>> output = ops.crop_and_resize(Tensor(image), Tensor(boxes), Tensor(box_indices), crop_size)
>>> print(output.shape)
 (5, 24, 24, 3)