Dropout

Transforms

class CoarseDropout(max_holes: int = 8, max_height: int = 8, max_width: int = 8, max_depth: int = 8, min_holes: int | None = None, min_height: int | None = None, min_width: int | None = None, min_depth: int | None = None, fill_value: int = 0, mask_fill_value: int | None = None, always_apply: bool = False, p: float = 0.5)[source]

Bases: DualTransform

CoarseDropout of the rectangular regions in the image.

Parameters:
  • max_holes (int) – Maximum number of regions to zero out.

  • max_height (int, float) – Maximum height of the hole. If float, it is calculated as a fraction of the image height.

  • max_width (int, float) – Maximum width of the hole. If float, it is calculated as a fraction of the image width.

  • max_depth (int, float) – Maximum depth of the hole. If float, it is calculated as a fraction of the image depth.

  • min_holes (int) – Minimum number of regions to zero out. If None, min_holes is be set to max_holes. Default: None.

  • min_height (int, float) – Minimum height of the hole. Default: None. If None, min_height is set to max_height. Default: None. If float, it is calculated as a fraction of the image height.

  • min_width (int, float) – Minimum width of the hole. If None, min_width is set to max_width. Default: None. If float, it is calculated as a fraction of the image width.

  • min_depth (int, float) – Minimum depth of the hole. If None, min_depth is set to max_depth. Default: None. If float, it is calculated as a fraction of the image depth.

  • fill_value (int, float, list of int, list of float) – value for dropped pixels.

  • mask_fill_value (int, float, list of int, list of float) – fill value for dropped pixels in mask. If None - mask is not affected. Default: None.

  • always_apply (bool) – whether to always apply the transformation. Default: False

  • p (float) – probability of applying the transform. Default: 0.5.

Targets:

image, mask, keypoints

Image types:

uint8, float32

Reference: | https://arxiv.org/abs/1708.04552 | https://github.com/uoguelph-mlrg/Cutout/blob/master/util/cutout.py | https://github.com/aleju/imgaug/blob/master/imgaug/augmenters/arithmetic.py

apply(img: ndarray, fill_value: int | float = 0, holes: Iterable[Tuple[int, int, int, int, int, int]] = (), **params) ndarray[source]

Applies the transformation to the image

apply_to_keypoints(keypoints: Sequence[Tuple[float, float, float, float] | Tuple[float, float, float, float, Any]], holes: Iterable[Tuple[int, int, int, int]] = (), **params) List[Tuple[float, float, float, float] | Tuple[float, float, float, float, Any]][source]

Applies the transformation to a sequence of keypoints

apply_to_mask(img: ndarray, mask_fill_value: int | float = 0, holes: Iterable[Tuple[int, int, int, int, int, int]] = (), **params) ndarray[source]

Applies the transformation to a mask

check_range(dimension)[source]
get_params_dependent_on_targets(params: Dict[str, Any]) Dict[str, Any][source]

Returns additional parameters needed for the apply methods that depend on a target (e.g. apply_to_bboxes method expects image size)

get_transform_init_args_names() Tuple[str, ...][source]

Returns initialization argument names. (e.g. Transform(arg1 = 1, arg2 = 2) -> (‘arg1’, ‘arg2’))

property targets_as_params: List[str]

Returns a list of target names (e.g. ‘image’) that are needed as a parameter input to other apply methods (e.g. apply_to_bboxes(…, image = image))

class GridDropout(ratio: float = 0.5, unit_size_min: int | None = None, unit_size_max: int | None = None, holes_number_x: int | None = None, holes_number_y: int | None = None, holes_number_z: int | None = None, shift_x: int = 0, shift_y: int = 0, shift_z: int = 0, random_offset: bool = False, fill_value: int = 0, mask_fill_value: int | None = None, always_apply: bool = False, p: float = 0.5)[source]

Bases: DualTransform

GridDropout, drops out rectangular regions of an image and the corresponding mask in a grid fashion.

Parameters:
  • ratio (float) – the ratio of the mask holes to the unit_size (same for all spatial dimensions). Must be between 0 and 1. Default: 0.5.

  • unit_size_min (int) – minimum size of the grid unit. Must be between 2 and the image shorter edge. If ‘None’, holes_number_x and holes_number_y are used to setup the grid. Default: None.

  • unit_size_max (int) – maximum size of the grid unit. Must be between 2 and the image shorter edge. If ‘None’, holes_number_x and holes_number_y are used to setup the grid. Default: None.

  • holes_number_x (int) – the number of grid units in x direction. Must be between 1 and image width//2. If ‘None’, grid unit width is set as image_width//10. Default: None.

  • holes_number_y (int) – the number of grid units in y direction. Must be between 1 and image height//2. If None, grid unit height is set equal to the grid unit width or image height, whatever is smaller.

  • holes_number_z (int) – the number of grid units in z direction. Must be between 1 and image depth//2. If None, grid unit depth is set equal to the grid unit width, height, whatever is smaller.

  • shift_x (int) – offsets of the grid start in x direction from (0,0) coordinate. Clipped between 0 and grid unit_width - hole_width. Default: 0.

  • shift_y (int) – offsets of the grid start in y direction from (0,0) coordinate. Clipped between 0 and grid unit height - hole_height. Default: 0.

  • shift_z (int) – offsets of the grid start in z direction from (0,0) coordinate. Clipped between 0 and grid unit depth - hole_height. Default: 0.

  • random_offset (boolean) – weather to offset the grid randomly between 0 and grid unit size - hole size If ‘True’, then shift_x, shift_y, shift_z are ignored and set randomly. Default: False.

  • fill_value (int) – value for the dropped pixels. Default = 0

  • mask_fill_value (int) – value for the dropped pixels in mask. If None, transformation is not applied to the mask. Default: None.

  • always_apply (bool) – whether to always apply the transformation. Default: False

  • p (float) – probability of applying the transform. Default: 0.5.

Targets:

image, mask

Image types:

uint8, float32

References

https://arxiv.org/abs/2001.04086

apply(img: ndarray, holes: Iterable[Tuple[int, int, int, int, int, int]] = (), **params) ndarray[source]

Applies the transformation to the image

apply_to_mask(img: ndarray, holes: Iterable[Tuple[int, int, int, int, int, int]] = (), **params) ndarray[source]

Applies the transformation to a mask and

get_params_dependent_on_targets(params) Dict[str, Any][source]

Returns additional parameters needed for the apply methods that depend on a target (e.g. apply_to_bboxes method expects image size)

get_transform_init_args_names() Tuple[str, ...][source]

Returns initialization argument names. (e.g. Transform(arg1 = 1, arg2 = 2) -> (‘arg1’, ‘arg2’))

property targets_as_params: List[str]

Returns a list of target names (e.g. ‘image’) that are needed as a parameter input to other apply methods (e.g. apply_to_bboxes(…, image = image))

Functional

cutout(img: ndarray, holes: Iterable[Tuple[int, int, int, int, int, int]], fill_value: int | float = 0) ndarray[source]

Puts holes in image.

Parameters:
  • img (np.ndarray) – an image

  • holes (Sequence of Tuples) – A sequence of indexing ranges for each dimension to create a hole in

  • fill_value (int,float) – The value to fill the holes with. Default: 0