Shortcuts

RandomResize

class mmpretrain.datasets.transforms.RandomResize(scale, ratio_range=None, resize_type='Resize', **resize_kwargs)[source]

Random resize images & bbox & keypoints.

How to choose the target scale to resize the image will follow the rules below:

  • if scale is a sequence of tuple

\[target\_scale[0] \sim Uniform([scale[0][0], scale[1][0]])\]
\[target\_scale[1] \sim Uniform([scale[0][1], scale[1][1]])\]

Following the resize order of weight and height in cv2, scale[i][0] is for width, and scale[i][1] is for height.

  • if scale is a tuple

\[target\_scale[0] \sim Uniform([ratio\_range[0], ratio\_range[1]]) * scale[0]\]
\[target\_scale[1] \sim Uniform([ratio\_range[0], ratio\_range[1]]) * scale[1]\]

Following the resize order of weight and height in cv2, ratio_range[0] is for width, and ratio_range[1] is for height.

  • if keep_ratio is True, the minimum value of target_scale will be used to set the shorter side and the maximum value will be used to set the longer side.

  • if keep_ratio is False, the value of target_scale will be used to reisze the width and height accordingly.

Required Keys:

  • img

  • gt_bboxes

  • gt_seg_map

  • gt_keypoints

Modified Keys:

  • img

  • gt_bboxes

  • gt_seg_map

  • gt_keypoints

  • img_shape

Added Keys:

  • scale

  • scale_factor

  • keep_ratio

Parameters:
  • scale (tuple or Sequence[tuple]) – Images scales for resizing. Defaults to None.

  • ratio_range (tuple[float], optional) – (min_ratio, max_ratio). Defaults to None.

  • resize_type (str) – The type of resize class to use. Defaults to “Resize”.

  • **resize_kwargs – Other keyword arguments for the resize_type.

Note

By defaults, the resize_type is “Resize”, if it’s not overwritten by your registry, it indicates the mmcv.Resize. And therefore, resize_kwargs accepts any keyword arguments of it, like keep_ratio, interpolation and so on.

If you want to use your custom resize class, the class should accept scale argument and have scale attribution which determines the resize shape.

transform(results)[source]

Transform function to resize images, bounding boxes, semantic segmentation map.

Parameters:

results (dict) – Result dict from loading pipeline.

Returns:

Resized results, img, gt_bboxes, gt_semantic_seg, gt_keypoints, scale, scale_factor, img_shape, and keep_ratio keys are updated in result dict.

Return type:

dict

Read the Docs v: latest
Versions
latest
stable
mmcls-1.x
mmcls-0.x
dev
Downloads
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.