pytorch_lightning_spells.cutmix_utils module

Functions:

cutmix_bbox_and_lam(img_shape, lam[, ...])

Generate bbox and apply lambda correction.

rand_bbox(img_shape, lam[, margin, count])

Standard CutMix bounding-box

rand_bbox_minmax(img_shape, minmax[, count])

Min-Max CutMix bounding-box

pytorch_lightning_spells.cutmix_utils.cutmix_bbox_and_lam(img_shape, lam, ratio_minmax=None, correct_lam=True, count=None)[source]

Generate bbox and apply lambda correction.

Parameters
  • img_shape (Tuple) –

  • count (Optional[int]) –

pytorch_lightning_spells.cutmix_utils.rand_bbox(img_shape, lam, margin=0.0, count=None)[source]

Standard CutMix bounding-box

Generates a random square bbox based on lambda value. This impl includes support for enforcing a border margin as percent of bbox dimensions.

Parameters
  • img_shape (Tuple) – Image shape as tuple

  • lam (float) – Cutmix lambda value

  • margin (float) – Percentage of bbox dimension to enforce as margin (reduce amount of box outside image)

  • count (Optional[int]) – Number of bbox to generate

pytorch_lightning_spells.cutmix_utils.rand_bbox_minmax(img_shape, minmax, count=None)[source]

Min-Max CutMix bounding-box

Inspired by Darknet cutmix impl, generates a random rectangular bbox based on min/max percent values applied to each dimension of the input image. Typical defaults for minmax are usually in the .2-.3 for min and .8-.9 range for max.

Parameters
  • img_shape (Tuple) – Image shape as tuple

  • minmax (Union[Tuple, List]) – Min and max bbox ratios (as percent of image size)

  • count (Optional[int]) – Number of bbox to generate