imgaug.augmentables.batches

Classes representing batches of normalized or unnormalized data.

class imgaug.augmentables.batches.Batch(images=None, heatmaps=None, segmentation_maps=None, keypoints=None, bounding_boxes=None, polygons=None, line_strings=None, data=None)[source]

Bases: object

Class encapsulating a batch before and after augmentation.

Parameters:
  • images (None or (N,H,W,C) ndarray or list of (H,W,C) ndarray) – The images to augment.
  • heatmaps (None or list of imgaug.augmentables.heatmaps.HeatmapsOnImage) – The heatmaps to augment.
  • segmentation_maps (None or list of imgaug.augmentables.segmaps.SegmentationMapsOnImage) – The segmentation maps to augment.
  • keypoints (None or list of imgaug.augmentables.kps.KeypointOnImage) – The keypoints to augment.
  • bounding_boxes (None or list of imgaug.augmentables.bbs.BoundingBoxesOnImage) – The bounding boxes to augment.
  • polygons (None or list of imgaug.augmentables.polys.PolygonsOnImage) – The polygons to augment.
  • line_strings (None or list of imgaug.augmentables.lines.LineStringsOnImage) – The line strings to augment.
  • data – Additional data that is saved in the batch and may be read out after augmentation. This could e.g. contain filepaths to each image in images. As this object is usually used for background augmentation with multiple processes, the augmented Batch objects might not be returned in the original order, making this information useful.
Attributes:
bounding_boxes

Deprecated. Use Batch.bounding_boxes_unaug instead.

heatmaps

Deprecated. Use Batch.heatmaps_unaug instead.

images

Deprecated. Use Batch.images_unaug instead.

keypoints

Deprecated. Use Batch.keypoints_unaug instead.

segmentation_maps

Deprecated. Use Batch.segmentation_maps_unaug instead.

Methods

deepcopy(self[, images_unaug, images_aug, …]) Copy this batch and all of its column values.
fill_from_batch_in_augmentation_(self, …) Set the columns in this batch to the column values of another batch.
get_column_names(self) Get the names of types of augmentables that contain data.
to_batch_in_augmentation(self) Convert this batch to a _BatchInAugmentation instance.
to_normalized_batch(self) Return this batch.
bounding_boxes

Deprecated. Use Batch.bounding_boxes_unaug instead.

Get unaugmented bounding boxes.

deepcopy(self, images_unaug='DEFAULT', images_aug='DEFAULT', heatmaps_unaug='DEFAULT', heatmaps_aug='DEFAULT', segmentation_maps_unaug='DEFAULT', segmentation_maps_aug='DEFAULT', keypoints_unaug='DEFAULT', keypoints_aug='DEFAULT', bounding_boxes_unaug='DEFAULT', bounding_boxes_aug='DEFAULT', polygons_unaug='DEFAULT', polygons_aug='DEFAULT', line_strings_unaug='DEFAULT', line_strings_aug='DEFAULT')[source]

Copy this batch and all of its column values.

Parameters:
  • images_unaug (imgaug.augmentables.batches.DEFAULT or None or (N,H,W,C) ndarray or list of (H,W,C) ndarray) – Copies the current attribute value without changes if set to imgaug.augmentables.batches.DEFAULT. Otherwise same as in Batch.__init__().
  • images_aug (imgaug.augmentables.batches.DEFAULT or None or (N,H,W,C) ndarray or list of (H,W,C) ndarray) – Copies the current attribute value without changes if set to imgaug.augmentables.batches.DEFAULT. Otherwise same as in Batch.__init__().
  • heatmaps_unaug (imgaug.augmentables.batches.DEFAULT or None or list of imgaug.augmentables.heatmaps.HeatmapsOnImage) – Copies the current attribute value without changes if set to imgaug.augmentables.batches.DEFAULT. Otherwise same as in Batch.__init__().
  • heatmaps_aug (imgaug.augmentables.batches.DEFAULT or None or list of imgaug.augmentables.heatmaps.HeatmapsOnImage) – Copies the current attribute value without changes if set to imgaug.augmentables.batches.DEFAULT. Otherwise same as in Batch.__init__().
  • segmentation_maps_unaug (imgaug.augmentables.batches.DEFAULT or None or list of imgaug.augmentables.segmaps.SegmentationMapsOnImage) – Copies the current attribute value without changes if set to imgaug.augmentables.batches.DEFAULT. Otherwise same as in Batch.__init__().
  • segmentation_maps_aug (imgaug.augmentables.batches.DEFAULT or None or list of imgaug.augmentables.segmaps.SegmentationMapsOnImage) – Copies the current attribute value without changes if set to imgaug.augmentables.batches.DEFAULT. Otherwise same as in Batch.__init__().
  • keypoints_unaug (imgaug.augmentables.batches.DEFAULT or None or list of imgaug.augmentables.kps.KeypointOnImage) – Copies the current attribute value without changes if set to imgaug.augmentables.batches.DEFAULT. Otherwise same as in Batch.__init__().
  • keypoints_aug (imgaug.augmentables.batches.DEFAULT or None or list of imgaug.augmentables.kps.KeypointOnImage) – Copies the current attribute value without changes if set to imgaug.augmentables.batches.DEFAULT. Otherwise same as in Batch.__init__().
  • bounding_boxes_unaug (imgaug.augmentables.batches.DEFAULT or None or list of imgaug.augmentables.bbs.BoundingBoxesOnImage) – Copies the current attribute value without changes if set to imgaug.augmentables.batches.DEFAULT. Otherwise same as in Batch.__init__().
  • bounding_boxes_aug (imgaug.augmentables.batches.DEFAULT or None or list of imgaug.augmentables.bbs.BoundingBoxesOnImage) – Copies the current attribute value without changes if set to imgaug.augmentables.batches.DEFAULT. Otherwise same as in Batch.__init__().
  • polygons_unaug (imgaug.augmentables.batches.DEFAULT or None or list of imgaug.augmentables.polys.PolygonsOnImage) – Copies the current attribute value without changes if set to imgaug.augmentables.batches.DEFAULT. Otherwise same as in Batch.__init__().
  • polygons_aug (imgaug.augmentables.batches.DEFAULT or None or list of imgaug.augmentables.polys.PolygonsOnImage) – Copies the current attribute value without changes if set to imgaug.augmentables.batches.DEFAULT. Otherwise same as in Batch.__init__().
  • line_strings_unaug (imgaug.augmentables.batches.DEFAULT or None or list of imgaug.augmentables.lines.LineStringsOnImage) – Copies the current attribute value without changes if set to imgaug.augmentables.batches.DEFAULT. Otherwise same as in Batch.__init__().
  • line_strings_aug (imgaug.augmentables.batches.DEFAULT or None or list of imgaug.augmentables.lines.LineStringsOnImage) – Copies the current attribute value without changes if set to imgaug.augmentables.batches.DEFAULT. Otherwise same as in Batch.__init__().
Returns:

Deep copy of the batch, optionally with new attributes.

Return type:

Batch

fill_from_batch_in_augmentation_(self, batch_in_augmentation)[source]

Set the columns in this batch to the column values of another batch.

This method works in-place.

Added in 0.4.0.

Parameters:batch_in_augmentation (_BatchInAugmentation) – Batch of which to use the column values. The values are not copied. Only their references are used.
Returns:The updated batch. (Modified in-place.)
Return type:Batch
get_column_names(self)[source]

Get the names of types of augmentables that contain data.

This method is intended for situations where one wants to know which data is contained in the batch that has to be augmented, visualized or something similar.

Added in 0.4.0.

Returns:Names of types of augmentables. E.g. ["images", "polygons"].
Return type:list of str
heatmaps

Deprecated. Use Batch.heatmaps_unaug instead.

Get unaugmented heatmaps.

images

Deprecated. Use Batch.images_unaug instead.

Get unaugmented images.

keypoints

Deprecated. Use Batch.keypoints_unaug instead.

Get unaugmented keypoints.

segmentation_maps

Deprecated. Use Batch.segmentation_maps_unaug instead.

Get unaugmented segmentation maps.

to_batch_in_augmentation(self)[source]

Convert this batch to a _BatchInAugmentation instance.

Added in 0.4.0.

Returns:The converted batch.
Return type:imgaug.augmentables.batches._BatchInAugmentation
to_normalized_batch(self)[source]

Return this batch.

This method does nothing and only exists to simplify interfaces that accept both UnnormalizedBatch and Batch.

Added in 0.4.0.

Returns:This batch (not copied).
Return type:imgaug.augmentables.batches.Batch
class imgaug.augmentables.batches.UnnormalizedBatch(images=None, heatmaps=None, segmentation_maps=None, keypoints=None, bounding_boxes=None, polygons=None, line_strings=None, data=None)[source]

Bases: object

Class for batches of unnormalized data before and after augmentation.

Parameters:
  • images (None or (N,H,W,C) ndarray or (N,H,W) ndarray or iterable of (H,W,C) ndarray or iterable of (H,W) ndarray) – The images to augment.

  • heatmaps (None or (N,H,W,C) ndarray or imgaug.augmentables.heatmaps.HeatmapsOnImage or iterable of (H,W,C) ndarray or iterable of imgaug.augmentables.heatmaps.HeatmapsOnImage) – The heatmaps to augment. If anything else than HeatmapsOnImage, then the number of heatmaps must match the number of images provided via parameter images. The number is contained either in N or the first iterable’s size.

  • segmentation_maps (None or (N,H,W) ndarray or imgaug.augmentables.segmaps.SegmentationMapsOnImage or iterable of (H,W) ndarray or iterable of imgaug.augmentables.segmaps.SegmentationMapsOnImage) – The segmentation maps to augment. If anything else than SegmentationMapsOnImage, then the number of segmaps must match the number of images provided via parameter images. The number is contained either in N or the first iterable’s size.

  • keypoints (None or list of (N,K,2) ndarray or tuple of number or imgaug.augmentables.kps.Keypoint or iterable of (K,2) ndarray or iterable of tuple of number or iterable of imgaug.augmentables.kps.Keypoint or iterable of imgaug.augmentables.kps.KeypointOnImage or iterable of iterable of tuple of number or iterable of iterable of imgaug.augmentables.kps.Keypoint) – The keypoints to augment. If a tuple (or iterable(s) of tuple), then iterpreted as (x,y) coordinates and must hence contain two numbers. A single tuple represents a single coordinate on one image, an iterable of tuples the coordinates on one image and an iterable of iterable of tuples the coordinates on several images. Analogous if Keypoint objects are used instead of tuples. If an ndarray, then N denotes the number of images and K the number of keypoints on each image. If anything else than KeypointsOnImage is provided, then the number of keypoint groups must match the number of images provided via parameter images. The number is contained e.g. in N or in case of “iterable of iterable of tuples” in the first iterable’s size.

  • bounding_boxes (None or (N,B,4) ndarray or tuple of number or imgaug.augmentables.bbs.BoundingBox or imgaug.augmentables.bbs.BoundingBoxesOnImage or iterable of (B,4) ndarray or iterable of tuple of number or iterable of imgaug.augmentables.bbs.BoundingBox or iterable of imgaug.augmentables.bbs.BoundingBoxesOnImage or iterable of iterable of tuple of number or iterable of iterable imgaug.augmentables.bbs.BoundingBox) – The bounding boxes to augment. This is analogous to the keypoints parameter. However, each tuple – and also the last index in case of arrays – has size 4, denoting the bounding box coordinates x1, y1, x2 and y2.

  • polygons (None or (N,#polys,#points,2) ndarray or imgaug.augmentables.polys.Polygon or imgaug.augmentables.polys.PolygonsOnImage or iterable of (#polys,#points,2) ndarray or iterable of tuple of number or iterable of imgaug.augmentables.kps.Keypoint or iterable of imgaug.augmentables.polys.Polygon or iterable of imgaug.augmentables.polys.PolygonsOnImage or iterable of iterable of (#points,2) ndarray or iterable of iterable of tuple of number or iterable of iterable of imgaug.augmentables.kps.Keypoint or iterable of iterable of imgaug.augmentables.polys.Polygon or iterable of iterable of iterable of tuple of number or iterable of iterable of iterable of tuple of imgaug.augmentables.kps.Keypoint) – The polygons to augment. This is similar to the keypoints parameter. However, each polygon may be made up of several (x,y) coordinates (three or more are required for valid polygons). The following datatypes will be interpreted as a single polygon on a single image:

    • imgaug.augmentables.polys.Polygon
    • iterable of tuple of number
    • iterable of imgaug.augmentables.kps.Keypoint

    The following datatypes will be interpreted as multiple polygons on a single image:

    • imgaug.augmentables.polys.PolygonsOnImage
    • iterable of imgaug.augmentables.polys.Polygon
    • iterable of iterable of tuple of number
    • iterable of iterable of imgaug.augmentables.kps.Keypoint
    • iterable of iterable of imgaug.augmentables.polys.Polygon

    The following datatypes will be interpreted as multiple polygons on multiple images:

    • (N,#polys,#points,2) ndarray
    • iterable of (#polys,#points,2) ndarray
    • iterable of iterable of (#points,2) ndarray
    • iterable of iterable of iterable of tuple of number
    • iterable of iterable of iterable of tuple of imgaug.augmentables.kps.Keypoint
  • line_strings (None or (N,#lines,#points,2) ndarray or imgaug.augmentables.lines.LineString or imgaug.augmentables.lines.LineStringOnImage or iterable of (#lines,#points,2) ndarray or iterable of tuple of number or iterable of imgaug.augmentables.kps.Keypoint or iterable of imgaug.augmentables.lines.LineString or iterable of imgaug.augmentables.lines.LineStringOnImage or iterable of iterable of (#points,2) ndarray or iterable of iterable of tuple of number or iterable of iterable of imgaug.augmentables.kps.Keypoint or iterable of iterable of imgaug.augmentables.polys.LineString or iterable of iterable of iterable of tuple of number or iterable of iterable of iterable of tuple of imgaug.augmentables.kps.Keypoint) – The line strings to augment. See polygons for more details as polygons follow a similar structure to line strings.

  • data – Additional data that is saved in the batch and may be read out after augmentation. This could e.g. contain filepaths to each image in images. As this object is usually used for background augmentation with multiple processes, the augmented Batch objects might not be returned in the original order, making this information useful.

Methods

fill_from_augmented_normalized_batch(self, …) Fill this batch with (normalized) augmentation results.
fill_from_augmented_normalized_batch_(self, …) Fill this batch with (normalized) augmentation results in-place.
get_column_names(self) Get the names of types of augmentables that contain data.
to_normalized_batch(self) Convert this unnormalized batch to an instance of Batch.
fill_from_augmented_normalized_batch(self, batch_aug_norm)[source]

Fill this batch with (normalized) augmentation results.

This method receives a (normalized) Batch instance, takes all *_aug attributes out if it and assigns them to this batch in unnormalized form. Hence, the datatypes of all *_aug attributes will match the datatypes of the *_unaug attributes.

Parameters:batch_aug_norm (imgaug.augmentables.batches.Batch) – Batch after normalization and augmentation.
Returns:New UnnormalizedBatch instance. All *_unaug attributes are taken from the old UnnormalizedBatch (without deepcopying them) and all *_aug attributes are taken from batch_normalized, converted to unnormalized form.
Return type:imgaug.augmentables.batches.UnnormalizedBatch
fill_from_augmented_normalized_batch_(self, batch_aug_norm)[source]

Fill this batch with (normalized) augmentation results in-place.

This method receives a (normalized) Batch instance, takes all *_aug attributes out if it and assigns them to this batch in unnormalized form. Hence, the datatypes of all *_aug attributes will match the datatypes of the *_unaug attributes.

Added in 0.4.0.

Parameters:batch_aug_norm (imgaug.augmentables.batches.Batch) – Batch after normalization and augmentation.
Returns:This instance itself. All *_unaug attributes are unchanged. All *_aug attributes are taken from batch_normalized, converted to unnormalized form.
Return type:imgaug.augmentables.batches.UnnormalizedBatch
get_column_names(self)[source]

Get the names of types of augmentables that contain data.

This method is intended for situations where one wants to know which data is contained in the batch that has to be augmented, visualized or something similar.

Added in 0.4.0.

Returns:Names of types of augmentables. E.g. ["images", "polygons"].
Return type:list of str
to_normalized_batch(self)[source]

Convert this unnormalized batch to an instance of Batch.

As this method is intended to be called before augmentation, it assumes that none of the *_aug attributes is yet set. It will produce an AssertionError otherwise.

The newly created Batch’s *_unaug attributes will match the ones in this batch, just in normalized form.

Returns:The batch, with *_unaug attributes being normalized.
Return type:imgaug.augmentables.batches.Batch