RandomFlip

class cocohelper.transforms.randomflip.RandomFlip[source]

Bases: Transform

Flip images and annotations in vertical and horizontal axes.

Parameters:
  • horizontal_prob – probability of the horizontal flip occurring [0-1].

  • vertical_prob – probability of the vertical flip occurring [0-1].

Method List

_flip_bbox(bbox, shape, horizontal, vertical)

_flip_img(img, horizontal, vertical)

_flip_segmentations(segmentation, shape, ...)

apply(img, anns)

Apply the transformation to the image array and its annotations.

compute_bbox_area(bbox)

Compute area from a bounding box.

transform_dataset(coco, out_dir)

Apply an abstract transformation on the whole dataset.

Attributes List

_abc_impl

Methods Details

static _flip_bbox(bbox, shape, horizontal, vertical)[source]
Parameters:
  • bbox (Tuple[int, int, int, int]) –

  • shape (Tuple[int, ...]) –

  • horizontal (bool) –

  • vertical (bool) –

Return type:

Tuple[int, int, int, int]

static _flip_img(img, horizontal, vertical)[source]
Parameters:
  • img (ndarray) –

  • horizontal (bool) –

  • vertical (bool) –

Return type:

ndarray

static _flip_segmentations(segmentation, shape, horizontal, vertical)[source]
Parameters:
  • segmentation (List[List[int]]) –

  • shape (Tuple[int, ...]) –

  • horizontal (bool) –

  • vertical (bool) –

Return type:

List[List[int]]

apply(img, anns)[source]

Apply the transformation to the image array and its annotations.

Parameters:
  • img (ndarray) – image array.

  • anns (List[dict]) – annotations for this image.

Returns:

Transformed image array and annotations.

Return type:

Tuple[ndarray, List[dict]]

static compute_bbox_area(bbox)

Compute area from a bounding box.

Parameters:

bbox (List[int]) – bounding box.

Returns:

The area inside the given bounding box.

Return type:

int

transform_dataset(coco, out_dir)

Apply an abstract transformation on the whole dataset.

TODO: should we apply on the whole dataset eagerly or use a lazy execution when the data is obtained?
  • In the first case, apply takes a COCODataset and returns a new modified COCODataset.

  • In the second case probably COCODataset should have a reference to a Transform and apply just-in-time when an element is retrieved.

Parameters:
  • coco (COCOHelper) –

  • out_dir (Union[str, Path]) –

Return type:

COCOHelper

Attribute Details

_abc_impl = <_abc._abc_data object>