imgaug.augmenters.meta¶
Augmenters that don’t apply augmentations themselves, but are needed for meta usage.
List of augmenters:
Augmenter
(base class for all augmenters)Sequential
SomeOf
OneOf
Sometimes
WithChannels
Identity
Noop
Lambda
AssertLambda
AssertShape
ChannelShuffle
Note: WithColorspace
is in color.py
.
-
class
imgaug.augmenters.meta.
AssertLambda
(func_images=None, func_heatmaps=None, func_segmentation_maps=None, func_keypoints=None, func_bounding_boxes=None, func_polygons=None, func_line_strings=None, seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]¶ Bases:
imgaug.augmenters.meta.Lambda
Assert conditions based on lambda-function to be the case for input data.
This augmenter applies a lambda function to each image or other input. The lambda function must return
True
orFalse
. IfFalse
is returned, an assertion error is produced.This is useful to ensure that generic assumption about the input data are actually the case and error out early otherwise.
Supported dtypes:
uint8
: yes; fully testeduint16
: yes; testeduint32
: yes; testeduint64
: yes; testedint8
: yes; testedint16
: yes; testedint32
: yes; testedint64
: yes; testedfloat16
: yes; testedfloat32
: yes; testedfloat64
: yes; testedfloat128
: yes; testedbool
: yes; tested
Parameters: func_images (None or callable, optional) – The function to call for each batch of images. It must follow the form:
function(images, random_state, parents, hooks)
and return either
True
(valid input) orFalse
(invalid input). It essentially re-uses the interface of_augment_images()
.func_heatmaps (None or callable, optional) – The function to call for each batch of heatmaps. It must follow the form:
function(heatmaps, random_state, parents, hooks)
and return either
True
(valid input) orFalse
(invalid input). It essentially re-uses the interface of_augment_heatmaps()
.func_segmentation_maps (None or callable, optional) – The function to call for each batch of segmentation maps. It must follow the form:
function(segmaps, random_state, parents, hooks)
and return either
True
(valid input) orFalse
(invalid input). It essentially re-uses the interface of_augment_segmentation_maps()
.func_keypoints (None or callable, optional) – The function to call for each batch of keypoints. It must follow the form:
function(keypoints_on_images, random_state, parents, hooks)
and return either
True
(valid input) orFalse
(invalid input). It essentially re-uses the interface of_augment_keypoints()
.func_bounding_boxes (None or callable, optional) – The function to call for each batch of bounding boxes. It must follow the form:
function(bounding_boxes_on_images, random_state, parents, hooks)
and return either
True
(valid input) orFalse
(invalid input). It essentially re-uses the interface of_augment_bounding_boxes()
.Added in 0.4.0.
func_polygons (None or callable, optional) – The function to call for each batch of polygons. It must follow the form:
function(polygons_on_images, random_state, parents, hooks)
and return either
True
(valid input) orFalse
(invalid input). It essentially re-uses the interface of_augment_polygons()
.func_line_strings (None or callable, optional) – The function to call for each batch of line strings. It must follow the form:
function(line_strings_on_images, random_state, parents, hooks)
and return either
True
(valid input) orFalse
(invalid input). It essentially re-uses the interface of_augment_line_strings()
.Added in 0.4.0.
seed (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See
__init__()
.name (None or str, optional) – See
__init__()
.random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – Old name for parameter seed. Its usage will not yet cause a deprecation warning, but it is still recommended to use seed now. Outdated since 0.4.0.
deterministic (bool, optional) – Deprecated since 0.4.0. See method
to_deterministic()
for an alternative and for details about what the “deterministic mode” actually does.
Methods
__call__
(self, \*args, \*\*kwargs)Alias for augment()
.augment
(self[, return_batch, hooks])Augment a batch. augment_batch
(self, batch[, hooks])Deprecated. augment_batch_
(self, batch[, parents, hooks])Augment a single batch in-place. augment_batches
(self, batches[, hooks, …])Augment multiple batches. augment_bounding_boxes
(self, …[, parents, …])Augment a batch of bounding boxes. augment_heatmaps
(self, heatmaps[, parents, …])Augment a batch of heatmaps. augment_image
(self, image[, hooks])Augment a single image. augment_images
(self, images[, parents, hooks])Augment a batch of images. augment_keypoints
(self, keypoints_on_images)Augment a batch of keypoints/landmarks. augment_line_strings
(self, …[, parents, hooks])Augment a batch of line strings. augment_polygons
(self, polygons_on_images[, …])Augment a batch of polygons. augment_segmentation_maps
(self, segmaps[, …])Augment a batch of segmentation maps. copy
(self)Create a shallow copy of this Augmenter instance. copy_random_state
(self, source[, recursive, …])Copy the RNGs from a source augmenter sequence. copy_random_state_
(self, source[, …])Copy the RNGs from a source augmenter sequence (in-place). deepcopy
(self)Create a deep copy of this Augmenter instance. draw_grid
(self, images, rows, cols)Augment images and draw the results as a single grid-like image. find_augmenters
(self, func[, parents, flat])Find augmenters that match a condition. find_augmenters_by_name
(self, name[, regex, …])Find augmenter(s) by name. find_augmenters_by_names
(self, names[, …])Find augmenter(s) by names. get_all_children
(self[, flat])Get all children of this augmenter as a list. get_children_lists
(self)Get a list of lists of children of this augmenter. get_parameters
(self)See get_parameters()
.localize_random_state
(self[, recursive])Assign augmenter-specific RNGs to this augmenter and its children. localize_random_state_
(self[, recursive])Assign augmenter-specific RNGs to this augmenter and its children. pool
(self[, processes, maxtasksperchild, seed])Create a pool used for multicore augmentation. remove_augmenters
(self, func[, copy, …])Remove this augmenter or children that match a condition. remove_augmenters_
(self, func[, parents])Remove in-place children of this augmenter that match a condition. remove_augmenters_inplace
(self, func[, parents])Deprecated. reseed
(self[, random_state, deterministic_too])Deprecated. seed_
(self[, entropy, deterministic_too])Seed this augmenter and all of its children. show_grid
(self, images, rows, cols)Augment images and plot the results as a single grid-like image. to_deterministic
(self[, n])Convert this augmenter from a stochastic to a deterministic one.
-
class
imgaug.augmenters.meta.
AssertShape
(shape, check_images=True, check_heatmaps=True, check_segmentation_maps=True, check_keypoints=True, check_bounding_boxes=True, check_polygons=True, check_line_strings=True, seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]¶ Bases:
imgaug.augmenters.meta.Lambda
Assert that inputs have a specified shape.
Supported dtypes:
uint8
: yes; fully testeduint16
: yes; testeduint32
: yes; testeduint64
: yes; testedint8
: yes; testedint16
: yes; testedint32
: yes; testedint64
: yes; testedfloat16
: yes; testedfloat32
: yes; testedfloat64
: yes; testedfloat128
: yes; testedbool
: yes; tested
Parameters: shape (tuple) – The expected shape, given as a
tuple
. The number of entries in thetuple
must match the number of dimensions, i.e. it must contain four entries for(N, H, W, C)
. If only a single entity is augmented, e.g. viaaugment_image()
, thenN
is1
in the input to this augmenter. Images that don’t have a channel axis will automatically have one assigned, i.e.C
is at least1
. For each component of thetuple
one of the following datatypes may be used:- If a component is
None
, any value for that dimensions is accepted. - If a component is
int
, exactly that value (and no other one) will be accepted for that dimension. - If a component is a
tuple
of twoint
s with valuesa
andb
, only a value within the interval[a, b)
will be accepted for that dimension. - If an entry is a
list
ofint
s, only a value from thatlist
will be accepted for that dimension.
- If a component is
check_images (bool, optional) – Whether to validate input images via the given shape.
check_heatmaps (bool, optional) – Whether to validate input heatmaps via the given shape. The number of heatmaps will be verified as
N
. For eachHeatmapsOnImage
instance its array’s height and width will be verified asH
andW
, but not the channel count.check_segmentation_maps (bool, optional) – Whether to validate input segmentation maps via the given shape. The number of segmentation maps will be verified as
N
. For eachSegmentationMapOnImage
instance its array’s height and width will be verified asH
andW
, but not the channel count.check_keypoints (bool, optional) – Whether to validate input keypoints via the given shape. This will check (a) the number of keypoints and (b) for each
KeypointsOnImage
instance the.shape
attribute, i.e. the shape of the corresponding image.check_bounding_boxes (bool, optional) – Whether to validate input bounding boxes via the given shape. This will check (a) the number of bounding boxes and (b) for each
BoundingBoxesOnImage
instance the.shape
attribute, i.e. the shape of the corresponding image.Added in 0.4.0.
check_polygons (bool, optional) – Whether to validate input polygons via the given shape. This will check (a) the number of polygons and (b) for each
PolygonsOnImage
instance the.shape
attribute, i.e. the shape of the corresponding image.check_line_strings (bool, optional) – Whether to validate input line strings via the given shape. This will check (a) the number of line strings and (b) for each
LineStringsOnImage
instance the.shape
attribute, i.e. the shape of the corresponding image.Added in 0.4.0.
seed (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See
__init__()
.name (None or str, optional) – See
__init__()
.random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – Old name for parameter seed. Its usage will not yet cause a deprecation warning, but it is still recommended to use seed now. Outdated since 0.4.0.
deterministic (bool, optional) – Deprecated since 0.4.0. See method
to_deterministic()
for an alternative and for details about what the “deterministic mode” actually does.
Examples
>>> import imgaug.augmenters as iaa >>> seq = iaa.Sequential([ >>> iaa.AssertShape((None, 32, 32, 3)), >>> iaa.Fliplr(0.5) >>> ])
Verify first for each image batch if it contains a variable number of
32x32
images with3
channels each. Only if that check succeeds, the horizontal flip will be executed. Otherwise an assertion error will be raised.>>> seq = iaa.Sequential([ >>> iaa.AssertShape((None, (32, 64), 32, [1, 3])), >>> iaa.Fliplr(0.5) >>> ])
Similar to the above example, but now the height may be in the interval
[32, 64)
and the number of channels may be either1
or3
.Methods
__call__
(self, \*args, \*\*kwargs)Alias for augment()
.augment
(self[, return_batch, hooks])Augment a batch. augment_batch
(self, batch[, hooks])Deprecated. augment_batch_
(self, batch[, parents, hooks])Augment a single batch in-place. augment_batches
(self, batches[, hooks, …])Augment multiple batches. augment_bounding_boxes
(self, …[, parents, …])Augment a batch of bounding boxes. augment_heatmaps
(self, heatmaps[, parents, …])Augment a batch of heatmaps. augment_image
(self, image[, hooks])Augment a single image. augment_images
(self, images[, parents, hooks])Augment a batch of images. augment_keypoints
(self, keypoints_on_images)Augment a batch of keypoints/landmarks. augment_line_strings
(self, …[, parents, hooks])Augment a batch of line strings. augment_polygons
(self, polygons_on_images[, …])Augment a batch of polygons. augment_segmentation_maps
(self, segmaps[, …])Augment a batch of segmentation maps. copy
(self)Create a shallow copy of this Augmenter instance. copy_random_state
(self, source[, recursive, …])Copy the RNGs from a source augmenter sequence. copy_random_state_
(self, source[, …])Copy the RNGs from a source augmenter sequence (in-place). deepcopy
(self)Create a deep copy of this Augmenter instance. draw_grid
(self, images, rows, cols)Augment images and draw the results as a single grid-like image. find_augmenters
(self, func[, parents, flat])Find augmenters that match a condition. find_augmenters_by_name
(self, name[, regex, …])Find augmenter(s) by name. find_augmenters_by_names
(self, names[, …])Find augmenter(s) by names. get_all_children
(self[, flat])Get all children of this augmenter as a list. get_children_lists
(self)Get a list of lists of children of this augmenter. get_parameters
(self)See get_parameters()
.localize_random_state
(self[, recursive])Assign augmenter-specific RNGs to this augmenter and its children. localize_random_state_
(self[, recursive])Assign augmenter-specific RNGs to this augmenter and its children. pool
(self[, processes, maxtasksperchild, seed])Create a pool used for multicore augmentation. remove_augmenters
(self, func[, copy, …])Remove this augmenter or children that match a condition. remove_augmenters_
(self, func[, parents])Remove in-place children of this augmenter that match a condition. remove_augmenters_inplace
(self, func[, parents])Deprecated. reseed
(self[, random_state, deterministic_too])Deprecated. seed_
(self[, entropy, deterministic_too])Seed this augmenter and all of its children. show_grid
(self, images, rows, cols)Augment images and plot the results as a single grid-like image. to_deterministic
(self[, n])Convert this augmenter from a stochastic to a deterministic one.
-
class
imgaug.augmenters.meta.
Augmenter
(seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]¶ Bases:
object
Base class for Augmenter objects. All augmenters derive from this class.
Parameters: seed (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – Seed to use for this augmenter’s random number generator (RNG) or alternatively an RNG itself. Setting this parameter allows to control/influence the random number sampling of this specific augmenter without affecting other augmenters. Usually, there is no need to set this parameter.
- If
None
: The global RNG is used (shared by all augmenters). - If
int
: The value will be used as a seed for a newRNG
instance. - If
RNG
: TheRNG
instance will be used without changes. - If
Generator
: A newRNG
instance will be created, containing that generator. - If
BitGenerator
: Will be wrapped in aGenerator
. Then similar behaviour toGenerator
parameters. - If
SeedSequence
: Will be wrapped in a new bit generator andGenerator
. Then similar behaviour toGenerator
parameters. - If
RandomState
: Similar behaviour toGenerator
. Outdated in numpy 1.17+.
If a new bit generator has to be created, it will be an instance of
numpy.random.SFC64
.Added in 0.4.0.
- If
name (None or str, optional) – Name given to the Augmenter instance. This name is used when converting the instance to a string, e.g. for
print
statements. It is also used forfind
,remove
or similar operations on augmenters with children. IfNone
,UnnamedX
will be used as the name, whereX
is the Augmenter’s class name.random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – Old name for parameter seed. Its usage will not yet cause a deprecation warning, but it is still recommended to use seed now. Outdated since 0.4.0.
deterministic (bool, optional) – Deprecated since 0.4.0. See method
to_deterministic()
for an alternative and for details about what the “deterministic mode” actually does.
Methods
__call__
(self, \*args, \*\*kwargs)Alias for augment()
.augment
(self[, return_batch, hooks])Augment a batch. augment_batch
(self, batch[, hooks])Deprecated. augment_batch_
(self, batch[, parents, hooks])Augment a single batch in-place. augment_batches
(self, batches[, hooks, …])Augment multiple batches. augment_bounding_boxes
(self, …[, parents, …])Augment a batch of bounding boxes. augment_heatmaps
(self, heatmaps[, parents, …])Augment a batch of heatmaps. augment_image
(self, image[, hooks])Augment a single image. augment_images
(self, images[, parents, hooks])Augment a batch of images. augment_keypoints
(self, keypoints_on_images)Augment a batch of keypoints/landmarks. augment_line_strings
(self, …[, parents, hooks])Augment a batch of line strings. augment_polygons
(self, polygons_on_images[, …])Augment a batch of polygons. augment_segmentation_maps
(self, segmaps[, …])Augment a batch of segmentation maps. copy
(self)Create a shallow copy of this Augmenter instance. copy_random_state
(self, source[, recursive, …])Copy the RNGs from a source augmenter sequence. copy_random_state_
(self, source[, …])Copy the RNGs from a source augmenter sequence (in-place). deepcopy
(self)Create a deep copy of this Augmenter instance. draw_grid
(self, images, rows, cols)Augment images and draw the results as a single grid-like image. find_augmenters
(self, func[, parents, flat])Find augmenters that match a condition. find_augmenters_by_name
(self, name[, regex, …])Find augmenter(s) by name. find_augmenters_by_names
(self, names[, …])Find augmenter(s) by names. get_all_children
(self[, flat])Get all children of this augmenter as a list. get_children_lists
(self)Get a list of lists of children of this augmenter. get_parameters
(self)Get the parameters of this augmenter. localize_random_state
(self[, recursive])Assign augmenter-specific RNGs to this augmenter and its children. localize_random_state_
(self[, recursive])Assign augmenter-specific RNGs to this augmenter and its children. pool
(self[, processes, maxtasksperchild, seed])Create a pool used for multicore augmentation. remove_augmenters
(self, func[, copy, …])Remove this augmenter or children that match a condition. remove_augmenters_
(self, func[, parents])Remove in-place children of this augmenter that match a condition. remove_augmenters_inplace
(self, func[, parents])Deprecated. reseed
(self[, random_state, deterministic_too])Deprecated. seed_
(self[, entropy, deterministic_too])Seed this augmenter and all of its children. show_grid
(self, images, rows, cols)Augment images and plot the results as a single grid-like image. to_deterministic
(self[, n])Convert this augmenter from a stochastic to a deterministic one. -
augment
(self, return_batch=False, hooks=None, **kwargs)[source]¶ Augment a batch.
This method is a wrapper around
UnnormalizedBatch
andaugment_batch()
. Hence, it supports the same datatypes asUnnormalizedBatch
.If return_batch was set to
False
(the default), the method will return a tuple of augmentables. It will return the same types of augmentables (but in augmented form) as input into the method. This behaviour is partly specific to the python version:In python 3.6+ (if
return_batch=False
):- Any number of augmentables may be provided as input.
- None of the provided named arguments has to be image or images (but of coarse you may provide them).
- The return order matches the order of the named arguments, e.g.
x_aug, y_aug, z_aug = augment(X=x, Y=y, Z=z)
.
In python <3.6 (if
return_batch=False
):- One or two augmentables may be used as input, not more than that.
- One of the input arguments has to be image or images.
- The augmented images are always returned first, independent
of the input argument order, e.g.
a_aug, b_aug = augment(b=b, images=a)
. This also means that the output of the function can only be one of the following three cases: a batch, list/array of images, tuple of images and something (like images + segmentation maps).
If return_batch was set to
True
, an instance ofUnnormalizedBatch
will be returned. The output is the same for all python version and any number or combination of augmentables may be provided.So, to keep code downward compatible for python <3.6, use one of the following three options:
- Use
batch = augment(images=X, ..., return_batch=True)
. - Call
images = augment(images=X)
. - Call
images, other = augment(images=X, <something_else>=Y)
.
All augmentables must be provided as named arguments. E.g.
augment(<array>)
will crash, butaugment(images=<array>)
will work.Parameters: image (None or (H,W,C) ndarray or (H,W) ndarray, optional) – The image to augment. Only this or images can be set, not both. If return_batch is
False
and the python version is below 3.6, either this or images must be provided.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, optional) – The images to augment. Only this or image can be set, not both. If return_batch is
False
and the python version is below 3.6, either this or image must be provided.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, optional) – 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 inN
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, optional) – 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 inN
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, optional) – 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 ifKeypoint
instances are used instead of tuples. If an ndarray, thenN
denotes the number of images andK
the number of keypoints on each image. If anything else thanKeypointsOnImage
is provided, then the number of keypoint groups must match the number of images provided via parameter images. The number is contained e.g. inN
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, optional) – 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 coordinatesx1
,y1
,x2
andy2
.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, optional) – 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 (#polys,#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.lines.LineString or iterable of iterable of iterable of tuple of number or iterable of iterable of iterable of tuple of imgaug.augmentables.kps.Keypoint, optional) – The line strings to augment. See polygons, which behaves similarly.
return_batch (bool, optional) – Whether to return an instance of
UnnormalizedBatch
. If the python version is below 3.6 and more than two augmentables were provided (e.g. images, keypoints and polygons), then this must be set toTrue
. Otherwise an error will be raised.hooks (None or imgaug.imgaug.HooksImages, optional) – Hooks object to dynamically interfere with the augmentation process.
Returns: If return_batch was set to
True
, a instance ofUnnormalizedBatch
will be returned. If return_batch was set toFalse
, a tuple of augmentables will be returned, e.g.(augmented images, augmented keypoints)
. The datatypes match the input datatypes of the corresponding named arguments. In python <3.6, augmented images are always the first entry in the returned tuple. In python 3.6+ the order matches the order of the named arguments.Return type: Examples
>>> import numpy as np >>> import imgaug as ia >>> import imgaug.augmenters as iaa >>> aug = iaa.Affine(rotate=(-25, 25)) >>> image = np.zeros((64, 64, 3), dtype=np.uint8) >>> keypoints = [(10, 20), (30, 32)] # (x,y) coordinates >>> images_aug, keypoints_aug = aug.augment( >>> image=image, keypoints=keypoints)
Create a single image and a set of two keypoints on it, then augment both by applying a random rotation between
-25
deg and+25
deg. The sampled rotation value is automatically aligned between image and keypoints. Note that in python <3.6, augmented images will always be returned first, independent of the order of the named input arguments. Sokeypoints_aug, images_aug = aug.augment(keypoints=keypoints, image=image)
would not be correct (but in python 3.6+ it would be).>>> import numpy as np >>> import imgaug as ia >>> import imgaug.augmenters as iaa >>> from imgaug.augmentables.bbs import BoundingBox >>> aug = iaa.Affine(rotate=(-25, 25)) >>> images = [np.zeros((64, 64, 3), dtype=np.uint8), >>> np.zeros((32, 32, 3), dtype=np.uint8)] >>> keypoints = [[(10, 20), (30, 32)], # KPs on first image >>> [(22, 10), (12, 14)]] # KPs on second image >>> bbs = [ >>> [BoundingBox(x1=5, y1=5, x2=50, y2=45)], >>> [BoundingBox(x1=4, y1=6, x2=10, y2=15), >>> BoundingBox(x1=8, y1=9, x2=16, y2=30)] >>> ] # one BB on first image, two BBs on second image >>> batch_aug = aug.augment( >>> images=images, keypoints=keypoints, bounding_boxes=bbs, >>> return_batch=True)
Create two images of size
64x64
and32x32
, two sets of keypoints (each containing two keypoints) and two sets of bounding boxes (the first containing one bounding box, the second two bounding boxes). These augmentables are then augmented by applying random rotations between-25
deg and+25
deg to them. The rotation values are sampled by image and aligned between all augmentables on the same image. The method finally returns an instance ofUnnormalizedBatch
from which the augmented data can be retrieved viabatch_aug.images_aug
,batch_aug.keypoints_aug
, andbatch_aug.bounding_boxes_aug
. In python 3.6+, return_batch can be kept atFalse
and the augmented data can be retrieved asimages_aug, keypoints_aug, bbs_aug = augment(...)
.
-
augment_batch
(self, batch, hooks=None)[source]¶ Deprecated. Use
augment_batch_()
instead. augment_batch() was renamed to augment_batch_() as it changes all *_unaug attributes of batches in-place. Note that augment_batch_() has now a parents parameter. Calls of the style augment_batch(batch, hooks) must be changed to augment_batch(batch, hooks=hooks).Augment a single batch.
Deprecated since 0.4.0.
-
augment_batch_
(self, batch, parents=None, hooks=None)[source]¶ Augment a single batch in-place.
Added in 0.4.0.
Parameters: batch (imgaug.augmentables.batches.Batch or imgaug.augmentables.batches.UnnormalizedBatch or imgaug.augmentables.batch._BatchInAugmentation) – A single batch to augment.
If
imgaug.augmentables.batches.UnnormalizedBatch
orimgaug.augmentables.batches.Batch
, then the*_aug
attributes may be modified in-place, while the*_unaug
attributes will not be modified. Ifimgaug.augmentables.batches._BatchInAugmentation
, then all attributes may be modified in-place.parents (None or list of imgaug.augmenters.Augmenter, optional) – Parent augmenters that have previously been called before the call to this function. Usually you can leave this parameter as
None
. It is set automatically for child augmenters.hooks (None or imgaug.HooksImages, optional) – HooksImages object to dynamically interfere with the augmentation process.
Returns: Augmented batch.
Return type: imgaug.augmentables.batches.Batch or imgaug.augmentables.batches.UnnormalizedBatch
-
augment_batches
(self, batches, hooks=None, background=False)[source]¶ Augment multiple batches.
In contrast to other
augment_*
method, this one yields batches instead of returning a full list. This is more suited for most training loops.This method also also supports augmentation on multiple cpu cores, activated via the background flag. If the background flag is activated, an instance of
Pool
will be spawned using all available logical CPU cores and anoutput_buffer_size
ofC*10
, whereC
is the number of logical CPU cores. I.e. a maximum ofC*10
batches will be somewhere in the augmentation pipeline (or waiting to be retrieved by downstream functions) before this method temporarily stops the loading of new batches from batches.Parameters: - batches (imgaug.augmentables.batches.Batch or imgaug.augmentables.batches.UnnormalizedBatch or iterable of imgaug.augmentables.batches.Batch or iterable of imgaug.augmentables.batches.UnnormalizedBatch) – A single batch or a list of batches to augment.
- hooks (None or imgaug.HooksImages, optional) – HooksImages object to dynamically interfere with the augmentation process.
- background (bool, optional) – Whether to augment the batches in background processes.
If
True
, hooks can currently not be used as that would require pickling functions. Note that multicore augmentation distributes the batches onto different CPU cores. It does not split the data within batches. It is therefore not sensible to usebackground=True
to augment a single batch. Only use it for multiple batches. Note also that multicore augmentation needs some time to start. It is therefore not recommended to use it for very few batches.
Yields: imgaug.augmentables.batches.Batch or imgaug.augmentables.batches.UnnormalizedBatch or iterable of imgaug.augmentables.batches.Batch or iterable of imgaug.augmentables.batches.UnnormalizedBatch – Augmented batches.
-
augment_bounding_boxes
(self, bounding_boxes_on_images, parents=None, hooks=None)[source]¶ Augment a batch of bounding boxes.
This is the corresponding function to
Augmenter.augment_images()
, just for bounding boxes. Usually you will want to callAugmenter.augment_images()
with a list of images, e.g.augment_images([A, B, C])
and thenaugment_bounding_boxes()
with the corresponding list of bounding boxes on these images, e.g.augment_bounding_boxes([Abb, Bbb, Cbb])
, whereAbb
are the bounding boxes on imageA
.Make sure to first convert the augmenter(s) to deterministic states before augmenting images and their corresponding bounding boxes, e.g. by
>>> import imgaug.augmenters as iaa >>> from imgaug.augmentables.bbs import BoundingBox >>> from imgaug.augmentables.bbs import BoundingBoxesOnImage >>> A = B = C = np.ones((10, 10), dtype=np.uint8) >>> Abb = Bbb = Cbb = BoundingBoxesOnImage([ >>> BoundingBox(1, 1, 9, 9)], (10, 10)) >>> seq = iaa.Fliplr(0.5) >>> seq_det = seq.to_deterministic() >>> imgs_aug = seq_det.augment_images([A, B, C]) >>> bbs_aug = seq_det.augment_bounding_boxes([Abb, Bbb, Cbb])
Otherwise, different random values will be sampled for the image and bounding box augmentations, resulting in different augmentations (e.g. images might be rotated by
30deg
and bounding boxes by-10deg
). Also make sure to callAugmenter.to_deterministic()
again for each new batch, otherwise you would augment all batches in the same way.Note that there is also
Augmenter.augment()
, which automatically handles the random state alignment.Parameters: - bounding_boxes_on_images (imgaug.augmentables.bbs.BoundingBoxesOnImage or list of imgaug.augmentables.bbs.BoundingBoxesOnImage) – The bounding boxes to augment.
Either a single instance of
BoundingBoxesOnImage
or a list of such instances, with each one of them containing the bounding boxes of a single image. - parents (None or list of imgaug.augmenters.meta.Augmenter, optional) – Parent augmenters that have previously been called before the
call to this function. Usually you can leave this parameter as
None
. It is set automatically for child augmenters. - hooks (None or imgaug.imgaug.HooksKeypoints, optional) –
HooksKeypoints
object to dynamically interfere with the augmentation process.
Returns: Augmented bounding boxes.
Return type: imgaug.augmentables.bbs.BoundingBoxesOnImage or list of imgaug.augmentables.bbs.BoundingBoxesOnImage
- bounding_boxes_on_images (imgaug.augmentables.bbs.BoundingBoxesOnImage or list of imgaug.augmentables.bbs.BoundingBoxesOnImage) – The bounding boxes to augment.
Either a single instance of
-
augment_heatmaps
(self, heatmaps, parents=None, hooks=None)[source]¶ Augment a batch of heatmaps.
Parameters: - heatmaps (imgaug.augmentables.heatmaps.HeatmapsOnImage or list of imgaug.augmentables.heatmaps.HeatmapsOnImage) – Heatmap(s) to augment. Either a single heatmap or a list of heatmaps.
- parents (None or list of imgaug.augmenters.meta.Augmenter, optional) – Parent augmenters that have previously been called before the
call to this function. Usually you can leave this parameter as
None
. It is set automatically for child augmenters. - hooks (None or imaug.imgaug.HooksHeatmaps, optional) –
HooksHeatmaps
object to dynamically interfere with the augmentation process.
Returns: Corresponding augmented heatmap(s).
Return type: imgaug.augmentables.heatmaps.HeatmapsOnImage or list of imgaug.augmentables.heatmaps.HeatmapsOnImage
-
augment_image
(self, image, hooks=None)[source]¶ Augment a single image.
Parameters: - image ((H,W,C) ndarray or (H,W) ndarray) – The image to augment.
Channel-axis is optional, but expected to be the last axis if
present. In most cases, this array should be of dtype
uint8
, which is supported by all augmenters. Support for other dtypes varies by augmenter – see the respective augmenter-specific documentation for more details. - hooks (None or imgaug.HooksImages, optional) – HooksImages object to dynamically interfere with the augmentation process.
Returns: The corresponding augmented image.
Return type: ndarray
- image ((H,W,C) ndarray or (H,W) ndarray) – The image to augment.
Channel-axis is optional, but expected to be the last axis if
present. In most cases, this array should be of dtype
-
augment_images
(self, images, parents=None, hooks=None)[source]¶ Augment a batch of images.
Parameters: - images ((N,H,W,C) ndarray or (N,H,W) ndarray or list of (H,W,C) ndarray or list of (H,W) ndarray) – Images to augment.
The input can be a list of numpy arrays or a single array. Each
array is expected to have shape
(H, W, C)
or(H, W)
, whereH
is the height,W
is the width andC
are the channels. The number of channels may differ between images. If a list is provided, the height, width and channels may differ between images within the provided batch. In most cases, the image array(s) should be of dtypeuint8
, which is supported by all augmenters. Support for other dtypes varies by augmenter – see the respective augmenter-specific documentation for more details. - parents (None or list of imgaug.augmenters.Augmenter, optional) – Parent augmenters that have previously been called before the
call to this function. Usually you can leave this parameter as
None
. It is set automatically for child augmenters. - hooks (None or imgaug.imgaug.HooksImages, optional) –
HooksImages
object to dynamically interfere with the augmentation process.
Returns: Corresponding augmented images. If the input was an
ndarray
, the output is also anndarray
, unless the used augmentations have led to different output image sizes (as can happen in e.g. cropping).Return type: ndarray or list
Examples
>>> import imgaug.augmenters as iaa >>> import numpy as np >>> aug = iaa.GaussianBlur((0.0, 3.0)) >>> # create empty example images >>> images = np.zeros((2, 64, 64, 3), dtype=np.uint8) >>> images_aug = aug.augment_images(images)
Create
2
empty (i.e. black) example numpy images and apply gaussian blurring to them.- images ((N,H,W,C) ndarray or (N,H,W) ndarray or list of (H,W,C) ndarray or list of (H,W) ndarray) – Images to augment.
The input can be a list of numpy arrays or a single array. Each
array is expected to have shape
-
augment_keypoints
(self, keypoints_on_images, parents=None, hooks=None)[source]¶ Augment a batch of keypoints/landmarks.
This is the corresponding function to
Augmenter.augment_images()
, just for keypoints/landmarks (i.e. points on images). Usually you will want to callAugmenter.augment_images()
with a list of images, e.g.augment_images([A, B, C])
and thenaugment_keypoints()
with the corresponding list of keypoints on these images, e.g.augment_keypoints([Ak, Bk, Ck])
, whereAk
are the keypoints on imageA
.Make sure to first convert the augmenter(s) to deterministic states before augmenting images and their corresponding keypoints, e.g. by
>>> import imgaug.augmenters as iaa >>> from imgaug.augmentables.kps import Keypoint >>> from imgaug.augmentables.kps import KeypointsOnImage >>> A = B = C = np.zeros((10, 10), dtype=np.uint8) >>> Ak = Bk = Ck = KeypointsOnImage([Keypoint(2, 2)], (10, 10)) >>> seq = iaa.Fliplr(0.5) >>> seq_det = seq.to_deterministic() >>> imgs_aug = seq_det.augment_images([A, B, C]) >>> kps_aug = seq_det.augment_keypoints([Ak, Bk, Ck])
Otherwise, different random values will be sampled for the image and keypoint augmentations, resulting in different augmentations (e.g. images might be rotated by
30deg
and keypoints by-10deg
). Also make sure to callAugmenter.to_deterministic()
again for each new batch, otherwise you would augment all batches in the same way.Note that there is also
Augmenter.augment()
, which automatically handles the random state alignment.Parameters: - keypoints_on_images (imgaug.augmentables.kps.KeypointsOnImage or list of imgaug.augmentables.kps.KeypointsOnImage) – The keypoints/landmarks to augment.
Either a single instance of
KeypointsOnImage
or a list of such instances. Each instance must contain the keypoints of a single image. - parents (None or list of imgaug.augmenters.meta.Augmenter, optional) – Parent augmenters that have previously been called before the
call to this function. Usually you can leave this parameter as
None
. It is set automatically for child augmenters. - hooks (None or imgaug.imgaug.HooksKeypoints, optional) –
HooksKeypoints
object to dynamically interfere with the augmentation process.
Returns: Augmented keypoints.
Return type: imgaug.augmentables.kps.KeypointsOnImage or list of imgaug.augmentables.kps.KeypointsOnImage
- keypoints_on_images (imgaug.augmentables.kps.KeypointsOnImage or list of imgaug.augmentables.kps.KeypointsOnImage) – The keypoints/landmarks to augment.
Either a single instance of
-
augment_line_strings
(self, line_strings_on_images, parents=None, hooks=None)[source]¶ Augment a batch of line strings.
This is the corresponding function to
Augmenter.augment_images`()
, just for line strings. Usually you will want to callAugmenter.augment_images()
with a list of images, e.g.augment_images([A, B, C])
and thenaugment_line_strings()
with the corresponding list of line strings on these images, e.g.augment_line_strings([A_line, B_line, C_line])
, whereA_line
are the line strings on imageA
.Make sure to first convert the augmenter(s) to deterministic states before augmenting images and their corresponding line strings, e.g. by
>>> import imgaug.augmenters as iaa >>> from imgaug.augmentables.lines import LineString >>> from imgaug.augmentables.lines import LineStringsOnImage >>> A = B = C = np.ones((10, 10), dtype=np.uint8) >>> A_line = B_line = C_line = LineStringsOnImage( >>> [LineString([(0, 0), (1, 0), (1, 1), (0, 1)])], >>> shape=(10, 10)) >>> seq = iaa.Fliplr(0.5) >>> seq_det = seq.to_deterministic() >>> imgs_aug = seq_det.augment_images([A, B, C]) >>> lines_aug = seq_det.augment_line_strings([A_line, B_line, C_line])
Otherwise, different random values will be sampled for the image and line string augmentations, resulting in different augmentations (e.g. images might be rotated by
30deg
and line strings by-10deg
). Also make sure to callto_deterministic()
again for each new batch, otherwise you would augment all batches in the same way.Note that there is also
Augmenter.augment()
, which automatically handles the random state alignment.Parameters: - line_strings_on_images (imgaug.augmentables.lines.LineStringsOnImage or list of imgaug.augmentables.lines.LineStringsOnImage) – The line strings to augment.
Either a single instance of
LineStringsOnImage
or a list of such instances, with each one of them containing the line strings of a single image. - parents (None or list of imgaug.augmenters.meta.Augmenter, optional) – Parent augmenters that have previously been called before the call to this function. Usually you can leave this parameter as None. It is set automatically for child augmenters.
- hooks (None or imgaug.imgaug.HooksKeypoints, optional) –
HooksKeypoints
object to dynamically interfere with the augmentation process.
Returns: Augmented line strings.
Return type: imgaug.augmentables.lines.LineStringsOnImage or list of imgaug.augmentables.lines.LineStringsOnImage
- line_strings_on_images (imgaug.augmentables.lines.LineStringsOnImage or list of imgaug.augmentables.lines.LineStringsOnImage) – The line strings to augment.
Either a single instance of
-
augment_polygons
(self, polygons_on_images, parents=None, hooks=None)[source]¶ Augment a batch of polygons.
This is the corresponding function to
Augmenter.augment_images()
, just for polygons. Usually you will want to callAugmenter.augment_images`()
with a list of images, e.g.augment_images([A, B, C])
and thenaugment_polygons()
with the corresponding list of polygons on these images, e.g.augment_polygons([A_poly, B_poly, C_poly])
, whereA_poly
are the polygons on imageA
.Make sure to first convert the augmenter(s) to deterministic states before augmenting images and their corresponding polygons, e.g. by
>>> import imgaug.augmenters as iaa >>> from imgaug.augmentables.polys import Polygon, PolygonsOnImage >>> A = B = C = np.ones((10, 10), dtype=np.uint8) >>> Apoly = Bpoly = Cpoly = PolygonsOnImage( >>> [Polygon([(0, 0), (1, 0), (1, 1), (0, 1)])], >>> shape=(10, 10)) >>> seq = iaa.Fliplr(0.5) >>> seq_det = seq.to_deterministic() >>> imgs_aug = seq_det.augment_images([A, B, C]) >>> polys_aug = seq_det.augment_polygons([Apoly, Bpoly, Cpoly])
Otherwise, different random values will be sampled for the image and polygon augmentations, resulting in different augmentations (e.g. images might be rotated by
30deg
and polygons by-10deg
). Also make sure to callto_deterministic()
again for each new batch, otherwise you would augment all batches in the same way.Note that there is also
Augmenter.augment()
, which automatically handles the random state alignment.Parameters: - polygons_on_images (imgaug.augmentables.polys.PolygonsOnImage or list of imgaug.augmentables.polys.PolygonsOnImage) – The polygons to augment.
Either a single instance of
PolygonsOnImage
or a list of such instances, with each one of them containing the polygons of a single image. - parents (None or list of imgaug.augmenters.meta.Augmenter, optional) – Parent augmenters that have previously been called before the
call to this function. Usually you can leave this parameter as
None
. It is set automatically for child augmenters. - hooks (None or imgaug.imgaug.HooksKeypoints, optional) –
HooksKeypoints
object to dynamically interfere with the augmentation process.
Returns: Augmented polygons.
Return type: imgaug.augmentables.polys.PolygonsOnImage or list of imgaug.augmentables.polys.PolygonsOnImage
- polygons_on_images (imgaug.augmentables.polys.PolygonsOnImage or list of imgaug.augmentables.polys.PolygonsOnImage) – The polygons to augment.
Either a single instance of
-
augment_segmentation_maps
(self, segmaps, parents=None, hooks=None)[source]¶ Augment a batch of segmentation maps.
Parameters: - segmaps (imgaug.augmentables.segmaps.SegmentationMapsOnImage or list of imgaug.augmentables.segmaps.SegmentationMapsOnImage) – Segmentation map(s) to augment. Either a single segmentation map or a list of segmentation maps.
- parents (None or list of imgaug.augmenters.meta.Augmenter, optional) – Parent augmenters that have previously been called before the
call to this function. Usually you can leave this parameter as
None
. It is set automatically for child augmenters. - hooks (None or imgaug.HooksHeatmaps, optional) –
HooksHeatmaps
object to dynamically interfere with the augmentation process.
Returns: Corresponding augmented segmentation map(s).
Return type: imgaug.augmentables.segmaps.SegmentationMapsOnImage or list of imgaug.augmentables.segmaps.SegmentationMapsOnImage
-
copy
(self)[source]¶ Create a shallow copy of this Augmenter instance.
Returns: Shallow copy of this Augmenter instance. Return type: imgaug.augmenters.meta.Augmenter
-
copy_random_state
(self, source, recursive=True, matching='position', matching_tolerant=True, copy_determinism=False)[source]¶ Copy the RNGs from a source augmenter sequence.
Parameters: - source (imgaug.augmenters.meta.Augmenter) – See
copy_random_state_()
. - recursive (bool, optional) – See
copy_random_state_()
. - matching ({‘position’, ‘name’}, optional) – See
copy_random_state_()
. - matching_tolerant (bool, optional) – See
copy_random_state_()
. - copy_determinism (bool, optional) – See
copy_random_state_()
.
Returns: Copy of the augmenter itself (with copied RNGs).
Return type: - source (imgaug.augmenters.meta.Augmenter) – See
-
copy_random_state_
(self, source, recursive=True, matching='position', matching_tolerant=True, copy_determinism=False)[source]¶ Copy the RNGs from a source augmenter sequence (in-place).
Note
The source augmenters are not allowed to use the global RNG. Call
localize_random_state_()
once on the source to localize all random states.Parameters: - source (imgaug.augmenters.meta.Augmenter) – The source augmenter(s) from where to copy the RNG(s).
The source may have children (e.g. the source can be a
Sequential
). - recursive (bool, optional) – Whether to copy the RNGs of the source augmenter and
all of its children (
True
) or just the source augmenter (False
). - matching ({‘position’, ‘name’}, optional) – Defines the matching mode to use during recursive copy.
This is used to associate source augmenters with target augmenters.
If
position
then the target and source sequences of augmenters are turned into flattened lists and are associated based on their list indices. Ifname
then the target and source augmenters are matched based on their names (i.e.augmenter.name
). - matching_tolerant (bool, optional) – Whether to use tolerant matching between source and target
augmenters. If set to
False
: Name matching will raise an exception for any target augmenter which’s name does not appear among the source augmenters. Position matching will raise an exception if source and target augmenter have an unequal number of children. - copy_determinism (bool, optional) – Whether to copy the
deterministic
attributes from source to target augmenters too.
Returns: The augmenter itself.
Return type: - source (imgaug.augmenters.meta.Augmenter) – The source augmenter(s) from where to copy the RNG(s).
The source may have children (e.g. the source can be a
-
deepcopy
(self)[source]¶ Create a deep copy of this Augmenter instance.
Returns: Deep copy of this Augmenter instance. Return type: imgaug.augmenters.meta.Augmenter
-
draw_grid
(self, images, rows, cols)[source]¶ Augment images and draw the results as a single grid-like image.
This method applies this augmenter to the provided images and returns a grid image of the results. Each cell in the grid contains a single augmented version of an input image.
If multiple input images are provided, the row count is multiplied by the number of images and each image gets its own row. E.g. for
images = [A, B]
,rows=2
,cols=3
:A A A B B B A A A B B B
for
images = [A]
,rows=2
,cols=3
:A A A A A A
Parameters: - images ((N,H,W,3) ndarray or (H,W,3) ndarray or (H,W) ndarray or list of (H,W,3) ndarray or list of (H,W) ndarray) – List of images to augment and draw in the grid.
If a list, then each element is expected to have shape
(H, W)
or(H, W, 3)
. If a single array, then it is expected to have shape(N, H, W, 3)
or(H, W, 3)
or(H, W)
. - rows (int) – Number of rows in the grid.
If
N
input images are given, this value will automatically be multiplied byN
to create rows for each image. - cols (int) – Number of columns in the grid.
Returns: The generated grid image with augmented versions of the input images. Here,
Hg
andWg
reference the output size of the grid, and not the sizes of the input images.Return type: (Hg, Wg, 3) ndarray
- images ((N,H,W,3) ndarray or (H,W,3) ndarray or (H,W) ndarray or list of (H,W,3) ndarray or list of (H,W) ndarray) – List of images to augment and draw in the grid.
If a list, then each element is expected to have shape
-
find_augmenters
(self, func, parents=None, flat=True)[source]¶ Find augmenters that match a condition.
This function will compare this augmenter and all of its children with a condition. The condition is a lambda function.
Parameters: - func (callable) – A function that receives a
Augmenter
instance and a list of parentAugmenter
instances and must returnTrue
, if that augmenter is valid match orFalse
otherwise. - parents (None or list of imgaug.augmenters.meta.Augmenter, optional) – List of parent augmenters.
Intended for nested calls and can usually be left as
None
. - flat (bool, optional) – Whether to return the result as a flat list (
True
) or a nested list (False
). In the latter case, the nesting matches each augmenters position among the children.
Returns: Nested list if flat was set to
False
. Flat list if flat was set toTrue
.Return type: list of imgaug.augmenters.meta.Augmenter
Examples
>>> import imgaug.augmenters as iaa >>> aug = iaa.Sequential([ >>> iaa.Fliplr(0.5, name="fliplr"), >>> iaa.Flipud(0.5, name="flipud") >>> ]) >>> print(aug.find_augmenters(lambda a, parents: a.name == "fliplr"))
Return the first child augmenter (
Fliplr
instance).- func (callable) – A function that receives a
-
find_augmenters_by_name
(self, name, regex=False, flat=True)[source]¶ Find augmenter(s) by name.
Parameters: - name (str) – Name of the augmenter(s) to search for.
- regex (bool, optional) – Whether name parameter is a regular expression.
- flat (bool, optional) – See
find_augmenters()
.
Returns: augmenters – Nested list if flat was set to
False
. Flat list if flat was set toTrue
.Return type: list of imgaug.augmenters.meta.Augmenter
-
find_augmenters_by_names
(self, names, regex=False, flat=True)[source]¶ Find augmenter(s) by names.
Parameters: - names (list of str) – Names of the augmenter(s) to search for.
- regex (bool, optional) – Whether names is a list of regular expressions. If it is, an augmenter is considered a match if at least one of these expressions is a match.
- flat (boolean, optional) – See
find_augmenters()
.
Returns: augmenters – Nested list if flat was set to
False
. Flat list if flat was set toTrue
.Return type: list of imgaug.augmenters.meta.Augmenter
-
get_all_children
(self, flat=False)[source]¶ Get all children of this augmenter as a list.
If the augmenter has no children, the returned list is empty.
Parameters: flat (bool) – If set to True
, the returned list will be flat.Returns: The children as a nested or flat list. Return type: list of imgaug.augmenters.meta.Augmenter
-
get_children_lists
(self)[source]¶ Get a list of lists of children of this augmenter.
For most augmenters, the result will be a single empty list. For augmenters with children it will often be a list with one sublist containing all children. In some cases the augmenter will contain multiple distinct lists of children, e.g. an if-list and an else-list. This will lead to a result consisting of a single list with multiple sublists, each representing the respective sublist of children.
E.g. for an if/else-augmenter that executes the children
A1
,A2
if a condition is met and otherwise executes the childrenB1
,B2
,B3
the result will be[[A1, A2], [B1, B2, B3]]
.IMPORTANT: While the topmost list may be newly created, each of the sublist must be editable inplace resulting in a changed children list of the augmenter. E.g. if an Augmenter
IfElse(condition, [A1, A2], [B1, B2, B3])
returns[[A1, A2], [B1, B2, B3]]
for a call toget_children_lists()
andA2
is removed inplace from[A1, A2]
, then the children lists ofIfElse(...)
must also change to[A1], [B1, B2, B3]
. This is used inremove_augmenters_()
.Returns: One or more lists of child augmenter. Can also be a single empty list. Return type: list of list of imgaug.augmenters.meta.Augmenter
-
get_parameters
(self)[source]¶ Get the parameters of this augmenter.
Returns: List of parameters of arbitrary types (usually child class of StochasticParameter
, but not guaranteed to be).Return type: list
-
localize_random_state
(self, recursive=True)[source]¶ Assign augmenter-specific RNGs to this augmenter and its children.
See
Augmenter.localize_random_state_()
for more details.Parameters: recursive (bool, optional) – See localize_random_state_()
.Returns: Copy of the augmenter and its children, with localized RNGs. Return type: imgaug.augmenters.meta.Augmenter
-
localize_random_state_
(self, recursive=True)[source]¶ Assign augmenter-specific RNGs to this augmenter and its children.
This method iterates over this augmenter and all of its children and replaces any pointer to the global RNG with a new local (i.e. augmenter-specific) RNG.
A random number generator (RNG) is used for the sampling of random values. The global random number generator exists exactly once throughout the library and is shared by many augmenters. A local RNG (usually) exists within exactly one augmenter and is only used by that augmenter.
Usually there is no need to change global into local RNGs. The only noteworthy exceptions are
- Whenever you want to use determinism (so that the global RNG is not accidentally reverted).
- Whenever you want to copy RNGs from one augmenter to another. (Copying the global RNG would usually not be useful. Copying the global RNG from augmenter A to B, then executing A and then B would result in B’s (global) RNG’s state having already changed because of A’s sampling. So the samples of A and B would differ.)
The case of determinism is handled automatically by
to_deterministic()
. Only when you copy RNGs (viacopy_random_state()
), you need to call this function first.Parameters: recursive (bool, optional) – Whether to localize the RNGs of the augmenter’s children too. Returns: Returns itself (with localized RNGs). Return type: imgaug.augmenters.meta.Augmenter
-
pool
(self, processes=None, maxtasksperchild=None, seed=None)[source]¶ Create a pool used for multicore augmentation.
Parameters: - processes (None or int, optional) – Same as in
__init__()
. The number of background workers. IfNone
, the number of the machine’s CPU cores will be used (this counts hyperthreads as CPU cores). If this is set to a negative valuep
, thenP - abs(p)
will be used, whereP
is the number of CPU cores. E.g.-1
would use all cores except one (this is useful to e.g. reserve one core to feed batches to the GPU). - maxtasksperchild (None or int, optional) – Same as for
__init__()
. The number of tasks done per worker process before the process is killed and restarted. IfNone
, worker processes will not be automatically restarted. - seed (None or int, optional) – Same as for
__init__()
. The seed to use for child processes. IfNone
, a random seed will be used.
Returns: Pool for multicore augmentation.
Return type: Examples
>>> import numpy as np >>> import imgaug as ia >>> import imgaug.augmenters as iaa >>> from imgaug.augmentables.batches import Batch >>> >>> aug = iaa.Add(1) >>> images = np.zeros((16, 128, 128, 3), dtype=np.uint8) >>> batches = [Batch(images=np.copy(images)) for _ in range(100)] >>> with aug.pool(processes=-1, seed=2) as pool: >>> batches_aug = pool.map_batches(batches, chunksize=8) >>> print(np.sum(batches_aug[0].images_aug[0])) 49152
Create
100
batches of empty images. Each batch contains16
images of size128x128
. The batches are then augmented on all CPU cores except one (processes=-1
). After augmentation, the sum of pixel values from the first augmented image is printed.>>> import numpy as np >>> import imgaug as ia >>> import imgaug.augmenters as iaa >>> from imgaug.augmentables.batches import Batch >>> >>> aug = iaa.Add(1) >>> images = np.zeros((16, 128, 128, 3), dtype=np.uint8) >>> def generate_batches(): >>> for _ in range(100): >>> yield Batch(images=np.copy(images)) >>> >>> with aug.pool(processes=-1, seed=2) as pool: >>> batches_aug = pool.imap_batches(generate_batches(), chunksize=8) >>> batch_aug = next(batches_aug) >>> print(np.sum(batch_aug.images_aug[0])) 49152
Same as above. This time, a generator is used to generate batches of images. Again, the first augmented image’s sum of pixels is printed.
- processes (None or int, optional) – Same as in
-
remove_augmenters
(self, func, copy=True, identity_if_topmost=True, noop_if_topmost=None)[source]¶ Remove this augmenter or children that match a condition.
Parameters: - func (callable) – Condition to match per augmenter.
The function must expect the augmenter itself and a list of parent
augmenters and returns
True
if that augmenter is supposed to be removed, orFalse
otherwise. E.g.lambda a, parents: a.name == "fliplr" and len(parents) == 1
removes an augmenter with namefliplr
if it is the direct child of the augmenter upon whichremove_augmenters()
was initially called. - copy (bool, optional) – Whether to copy this augmenter and all if its children before
removing. If
False
, removal is performed in-place. - identity_if_topmost (bool, optional) – If
True
and the condition (lambda function) leads to the removal of the topmost augmenter (the one this function is called on initially), then that topmost augmenter will be replaced by an instance ofNoop
(i.e. an augmenter that doesn’t change its inputs). IfFalse
,None
will be returned in these cases. This can only beFalse
if copy is set toTrue
. - noop_if_topmost (bool, optional) – Deprecated since 0.4.0.
Returns: This augmenter after the removal was performed.
None
is returned if the condition was matched for the topmost augmenter, copy was set toTrue
and noop_if_topmost was set toFalse
.Return type: imgaug.augmenters.meta.Augmenter or None
Examples
>>> import imgaug.augmenters as iaa >>> seq = iaa.Sequential([ >>> iaa.Fliplr(0.5, name="fliplr"), >>> iaa.Flipud(0.5, name="flipud"), >>> ]) >>> seq = seq.remove_augmenters(lambda a, parents: a.name == "fliplr")
This removes the augmenter
Fliplr
from theSequential
object’s children.- func (callable) – Condition to match per augmenter.
The function must expect the augmenter itself and a list of parent
augmenters and returns
-
remove_augmenters_
(self, func, parents=None)[source]¶ Remove in-place children of this augmenter that match a condition.
This is functionally identical to
remove_augmenters()
withcopy=False
, except that it does not affect the topmost augmenter (the one on which this function is initially called on).Added in 0.4.0.
Parameters: - func (callable) – See
remove_augmenters()
. - parents (None or list of imgaug.augmenters.meta.Augmenter, optional) – List of parent
Augmenter
instances that lead to this augmenter. IfNone
, an empty list will be used. This parameter can usually be left empty and will be set automatically for children.
Examples
>>> import imgaug.augmenters as iaa >>> seq = iaa.Sequential([ >>> iaa.Fliplr(0.5, name="fliplr"), >>> iaa.Flipud(0.5, name="flipud"), >>> ]) >>> seq.remove_augmenters_(lambda a, parents: a.name == "fliplr")
This removes the augmenter
Fliplr
from theSequential
object’s children.- func (callable) – See
-
remove_augmenters_inplace
(self, func, parents=None)[source]¶ Deprecated. Use
remove_augmenters_
instead.Old name for
remove_augmenters_()
.Deprecated since 0.4.0.
-
reseed
(self, random_state=None, deterministic_too=False)[source]¶ Deprecated. Use
imgaug.augmenters.meta.Augmenter.seed_
instead.Old name of
seed_()
.Deprecated since 0.4.0.
-
seed_
(self, entropy=None, deterministic_too=False)[source]¶ Seed this augmenter and all of its children.
This method assigns a new random number generator to the augmenter and all of its children (if it has any). The new random number generator is derived from the provided seed or RNG – or from the global random number generator if
None
was provided. Note that as child RNGs are derived, they do not all use the same seed.If this augmenter or any child augmenter had a random number generator that pointed to the global random state, it will automatically be replaced with a local random state. This is similar to what
localize_random_state()
does.This method is useful when augmentations are run in the background (i.e. on multiple cores). It should be called before sending this
Augmenter
instance to a background worker or once within each worker with different seeds (i.e., ifN
workers are used, the function should be calledN
times). Otherwise, all background workers will use the same seeds and therefore apply the same augmentations. Note thatAugmenter.augment_batches()
andAugmenter.pool()
already do this automatically.Added in 0.4.0.
Parameters: - entropy (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – A seed or random number generator that is used to derive new
random number generators for this augmenter and its children.
If an
int
is provided, it will be interpreted as a seed. IfNone
is provided, the global random number generator will be used. - deterministic_too (bool, optional) – Whether to also change the seed of an augmenter
A
, ifA
is deterministic. This is the case both when this augmenter object isA
or one of its children isA
.
Examples
>>> import imgaug.augmenters as iaa >>> aug = iaa.Sequential([ >>> iaa.Crop(px=(0, 10)), >>> iaa.Crop(px=(0, 10)) >>> ]) >>> aug.seed_(1)
Seed an augmentation sequence containing two crop operations. Even though the same seed was used, the two operations will still sample different pixel amounts to crop as the child-specific seed is merely derived from the provided seed.
- entropy (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – A seed or random number generator that is used to derive new
random number generators for this augmenter and its children.
If an
-
show_grid
(self, images, rows, cols)[source]¶ Augment images and plot the results as a single grid-like image.
This calls
draw_grid()
and simply shows the results. See that method for details.Parameters: - images ((N,H,W,3) ndarray or (H,W,3) ndarray or (H,W) ndarray or list of (H,W,3) ndarray or list of (H,W) ndarray) – List of images to augment and draw in the grid.
If a list, then each element is expected to have shape
(H, W)
or(H, W, 3)
. If a single array, then it is expected to have shape(N, H, W, 3)
or(H, W, 3)
or(H, W)
. - rows (int) – Number of rows in the grid.
If
N
input images are given, this value will automatically be multiplied byN
to create rows for each image. - cols (int) – Number of columns in the grid.
- images ((N,H,W,3) ndarray or (H,W,3) ndarray or (H,W) ndarray or list of (H,W,3) ndarray or list of (H,W) ndarray) – List of images to augment and draw in the grid.
If a list, then each element is expected to have shape
-
to_deterministic
(self, n=None)[source]¶ Convert this augmenter from a stochastic to a deterministic one.
A stochastic augmenter samples pseudo-random values for each parameter, image and batch. A deterministic augmenter also samples new values for each parameter and image, but not batch. Instead, for consecutive batches it will sample the same values (provided the number of images and their sizes don’t change). From a technical perspective this means that a deterministic augmenter starts each batch’s augmentation with a random number generator in the same state (i.e. same seed), instead of advancing that state from batch to batch.
Using determinism is useful to (a) get the same augmentations for two or more image batches (e.g. for stereo cameras), (b) to augment images and corresponding data on them (e.g. segmentation maps or bounding boxes) in the same way.
Parameters: n (None or int, optional) – Number of deterministic augmenters to return. If None
then only oneAugmenter
instance will be returned. If1
or higher, a list containingn
Augmenter
instances will be returned.Returns: A single Augmenter object if n was None, otherwise a list of Augmenter objects (even if n was 1
).Return type: imgaug.augmenters.meta.Augmenter or list of imgaug.augmenters.meta.Augmenter
-
class
imgaug.augmenters.meta.
ChannelShuffle
(p=1.0, channels=None, seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]¶ Bases:
imgaug.augmenters.meta.Augmenter
Randomize the order of channels in input images.
Supported dtypes:
uint8
: yes; fully testeduint16
: yes; testeduint32
: yes; testeduint64
: yes; testedint8
: yes; testedint16
: yes; testedint32
: yes; testedint64
: yes; testedfloat16
: yes; testedfloat32
: yes; testedfloat64
: yes; testedfloat128
: yes; testedbool
: yes; tested
Parameters: - p (float or imgaug.parameters.StochasticParameter, optional) – Probability of shuffling channels in any given image.
May be a fixed probability as a
float
, or aStochasticParameter
that returns0
s and1
s. - channels (None or imgaug.ALL or list of int, optional) – Which channels are allowed to be shuffled with each other.
If this is
None
orimgaug.ALL
, then all channels may be shuffled. If it is alist
ofint
s, then only the channels with indices in that list may be shuffled. (Values start at0
. All channel indices in the list must exist in each image.) - seed (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See
__init__()
. - name (None or str, optional) – See
__init__()
. - random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – Old name for parameter seed. Its usage will not yet cause a deprecation warning, but it is still recommended to use seed now. Outdated since 0.4.0.
- deterministic (bool, optional) – Deprecated since 0.4.0.
See method
to_deterministic()
for an alternative and for details about what the “deterministic mode” actually does.
Examples
>>> import imgaug.augmenters as iaa >>> aug = iaa.ChannelShuffle(0.35)
Shuffle all channels of
35%
of all images.>>> aug = iaa.ChannelShuffle(0.35, channels=[0, 1])
Shuffle only channels
0
and1
of35%
of all images. As the new channel orders0, 1
and1, 0
are both valid outcomes of the shuffling, it means that for0.35 * 0.5 = 0.175
or17.5%
of all images the order of channels0
and1
is inverted.Methods
__call__
(self, \*args, \*\*kwargs)Alias for augment()
.augment
(self[, return_batch, hooks])Augment a batch. augment_batch
(self, batch[, hooks])Deprecated. augment_batch_
(self, batch[, parents, hooks])Augment a single batch in-place. augment_batches
(self, batches[, hooks, …])Augment multiple batches. augment_bounding_boxes
(self, …[, parents, …])Augment a batch of bounding boxes. augment_heatmaps
(self, heatmaps[, parents, …])Augment a batch of heatmaps. augment_image
(self, image[, hooks])Augment a single image. augment_images
(self, images[, parents, hooks])Augment a batch of images. augment_keypoints
(self, keypoints_on_images)Augment a batch of keypoints/landmarks. augment_line_strings
(self, …[, parents, hooks])Augment a batch of line strings. augment_polygons
(self, polygons_on_images[, …])Augment a batch of polygons. augment_segmentation_maps
(self, segmaps[, …])Augment a batch of segmentation maps. copy
(self)Create a shallow copy of this Augmenter instance. copy_random_state
(self, source[, recursive, …])Copy the RNGs from a source augmenter sequence. copy_random_state_
(self, source[, …])Copy the RNGs from a source augmenter sequence (in-place). deepcopy
(self)Create a deep copy of this Augmenter instance. draw_grid
(self, images, rows, cols)Augment images and draw the results as a single grid-like image. find_augmenters
(self, func[, parents, flat])Find augmenters that match a condition. find_augmenters_by_name
(self, name[, regex, …])Find augmenter(s) by name. find_augmenters_by_names
(self, names[, …])Find augmenter(s) by names. get_all_children
(self[, flat])Get all children of this augmenter as a list. get_children_lists
(self)Get a list of lists of children of this augmenter. get_parameters
(self)See get_parameters()
.localize_random_state
(self[, recursive])Assign augmenter-specific RNGs to this augmenter and its children. localize_random_state_
(self[, recursive])Assign augmenter-specific RNGs to this augmenter and its children. pool
(self[, processes, maxtasksperchild, seed])Create a pool used for multicore augmentation. remove_augmenters
(self, func[, copy, …])Remove this augmenter or children that match a condition. remove_augmenters_
(self, func[, parents])Remove in-place children of this augmenter that match a condition. remove_augmenters_inplace
(self, func[, parents])Deprecated. reseed
(self[, random_state, deterministic_too])Deprecated. seed_
(self[, entropy, deterministic_too])Seed this augmenter and all of its children. show_grid
(self, images, rows, cols)Augment images and plot the results as a single grid-like image. to_deterministic
(self[, n])Convert this augmenter from a stochastic to a deterministic one. -
get_parameters
(self)[source]¶ See
get_parameters()
.
-
class
imgaug.augmenters.meta.
ClipCBAsToImagePlanes
(seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]¶ Bases:
imgaug.augmenters.meta.Augmenter
Clip coordinate-based augmentables to areas within the image plane.
This augmenter inspects all coordinate-based augmentables (e.g. bounding boxes, line strings) within a given batch and from each of them parts that are outside of the image plane. Parts within the image plane will be retained. This may e.g. shrink down bounding boxes. For keypoints, it removes any single points outside of the image plane. Any augmentable that is completely outside of the image plane will be removed.
Added in 0.4.0.
Supported dtypes:
uint8
: yes; fully testeduint16
: yes; fully testeduint32
: yes; fully testeduint64
: yes; fully testedint8
: yes; fully testedint16
: yes; fully testedint32
: yes; fully testedint64
: yes; fully testedfloat16
: yes; fully testedfloat32
: yes; fully testedfloat64
: yes; fully testedfloat128
: yes; fully testedbool
: yes; fully tested
Parameters: - seed (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See
__init__()
. - name (None or str, optional) – See
__init__()
. - random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – Old name for parameter seed. Its usage will not yet cause a deprecation warning, but it is still recommended to use seed now. Outdated since 0.4.0.
- deterministic (bool, optional) – Deprecated since 0.4.0.
See method
to_deterministic()
for an alternative and for details about what the “deterministic mode” actually does.
Examples
>>> import imgaug.augmenters as iaa >>> aug = iaa.Sequential([ >>> iaa.Affine(translate_px={"x": (-100, 100)}), >>> iaa.ClipCBAsToImagePlanes() >>> ])
Translate input data on the x-axis by
-100
to100
pixels, then cut all coordinate-based augmentables (e.g. bounding boxes) down to areas that are within the image planes of their corresponding images.Methods
__call__
(self, \*args, \*\*kwargs)Alias for augment()
.augment
(self[, return_batch, hooks])Augment a batch. augment_batch
(self, batch[, hooks])Deprecated. augment_batch_
(self, batch[, parents, hooks])Augment a single batch in-place. augment_batches
(self, batches[, hooks, …])Augment multiple batches. augment_bounding_boxes
(self, …[, parents, …])Augment a batch of bounding boxes. augment_heatmaps
(self, heatmaps[, parents, …])Augment a batch of heatmaps. augment_image
(self, image[, hooks])Augment a single image. augment_images
(self, images[, parents, hooks])Augment a batch of images. augment_keypoints
(self, keypoints_on_images)Augment a batch of keypoints/landmarks. augment_line_strings
(self, …[, parents, hooks])Augment a batch of line strings. augment_polygons
(self, polygons_on_images[, …])Augment a batch of polygons. augment_segmentation_maps
(self, segmaps[, …])Augment a batch of segmentation maps. copy
(self)Create a shallow copy of this Augmenter instance. copy_random_state
(self, source[, recursive, …])Copy the RNGs from a source augmenter sequence. copy_random_state_
(self, source[, …])Copy the RNGs from a source augmenter sequence (in-place). deepcopy
(self)Create a deep copy of this Augmenter instance. draw_grid
(self, images, rows, cols)Augment images and draw the results as a single grid-like image. find_augmenters
(self, func[, parents, flat])Find augmenters that match a condition. find_augmenters_by_name
(self, name[, regex, …])Find augmenter(s) by name. find_augmenters_by_names
(self, names[, …])Find augmenter(s) by names. get_all_children
(self[, flat])Get all children of this augmenter as a list. get_children_lists
(self)Get a list of lists of children of this augmenter. get_parameters
(self)See get_parameters()
.localize_random_state
(self[, recursive])Assign augmenter-specific RNGs to this augmenter and its children. localize_random_state_
(self[, recursive])Assign augmenter-specific RNGs to this augmenter and its children. pool
(self[, processes, maxtasksperchild, seed])Create a pool used for multicore augmentation. remove_augmenters
(self, func[, copy, …])Remove this augmenter or children that match a condition. remove_augmenters_
(self, func[, parents])Remove in-place children of this augmenter that match a condition. remove_augmenters_inplace
(self, func[, parents])Deprecated. reseed
(self[, random_state, deterministic_too])Deprecated. seed_
(self[, entropy, deterministic_too])Seed this augmenter and all of its children. show_grid
(self, images, rows, cols)Augment images and plot the results as a single grid-like image. to_deterministic
(self[, n])Convert this augmenter from a stochastic to a deterministic one. -
get_parameters
(self)[source]¶ See
get_parameters()
.
-
class
imgaug.augmenters.meta.
Identity
(seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]¶ Bases:
imgaug.augmenters.meta.Augmenter
Augmenter that does not change the input data.
This augmenter is useful e.g. during validation/testing as it allows to re-use the training code without actually performing any augmentation.
Added in 0.4.0.
Supported dtypes:
uint8
: yes; fully testeduint16
: yes; testeduint32
: yes; testeduint64
: yes; testedint8
: yes; testedint16
: yes; testedint32
: yes; testedint64
: yes; testedfloat16
: yes; testedfloat32
: yes; testedfloat64
: yes; testedfloat128
: yes; testedbool
: yes; tested
Parameters: - seed (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See
__init__()
. - name (None or str, optional) – See
__init__()
. - random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – Old name for parameter seed. Its usage will not yet cause a deprecation warning, but it is still recommended to use seed now. Outdated since 0.4.0.
- deterministic (bool, optional) – Deprecated since 0.4.0.
See method
to_deterministic()
for an alternative and for details about what the “deterministic mode” actually does.
Examples
>>> import imgaug.augmenters as iaa >>> aug = iaa.Identity()
Create an augmenter that does not change inputs.
Methods
__call__
(self, \*args, \*\*kwargs)Alias for augment()
.augment
(self[, return_batch, hooks])Augment a batch. augment_batch
(self, batch[, hooks])Deprecated. augment_batch_
(self, batch[, parents, hooks])Augment a single batch in-place. augment_batches
(self, batches[, hooks, …])Augment multiple batches. augment_bounding_boxes
(self, …[, parents, …])Augment a batch of bounding boxes. augment_heatmaps
(self, heatmaps[, parents, …])Augment a batch of heatmaps. augment_image
(self, image[, hooks])Augment a single image. augment_images
(self, images[, parents, hooks])Augment a batch of images. augment_keypoints
(self, keypoints_on_images)Augment a batch of keypoints/landmarks. augment_line_strings
(self, …[, parents, hooks])Augment a batch of line strings. augment_polygons
(self, polygons_on_images[, …])Augment a batch of polygons. augment_segmentation_maps
(self, segmaps[, …])Augment a batch of segmentation maps. copy
(self)Create a shallow copy of this Augmenter instance. copy_random_state
(self, source[, recursive, …])Copy the RNGs from a source augmenter sequence. copy_random_state_
(self, source[, …])Copy the RNGs from a source augmenter sequence (in-place). deepcopy
(self)Create a deep copy of this Augmenter instance. draw_grid
(self, images, rows, cols)Augment images and draw the results as a single grid-like image. find_augmenters
(self, func[, parents, flat])Find augmenters that match a condition. find_augmenters_by_name
(self, name[, regex, …])Find augmenter(s) by name. find_augmenters_by_names
(self, names[, …])Find augmenter(s) by names. get_all_children
(self[, flat])Get all children of this augmenter as a list. get_children_lists
(self)Get a list of lists of children of this augmenter. get_parameters
(self)See get_parameters()
.localize_random_state
(self[, recursive])Assign augmenter-specific RNGs to this augmenter and its children. localize_random_state_
(self[, recursive])Assign augmenter-specific RNGs to this augmenter and its children. pool
(self[, processes, maxtasksperchild, seed])Create a pool used for multicore augmentation. remove_augmenters
(self, func[, copy, …])Remove this augmenter or children that match a condition. remove_augmenters_
(self, func[, parents])Remove in-place children of this augmenter that match a condition. remove_augmenters_inplace
(self, func[, parents])Deprecated. reseed
(self[, random_state, deterministic_too])Deprecated. seed_
(self[, entropy, deterministic_too])Seed this augmenter and all of its children. show_grid
(self, images, rows, cols)Augment images and plot the results as a single grid-like image. to_deterministic
(self[, n])Convert this augmenter from a stochastic to a deterministic one. -
get_parameters
(self)[source]¶ See
get_parameters()
.
-
class
imgaug.augmenters.meta.
Lambda
(func_images=None, func_heatmaps=None, func_segmentation_maps=None, func_keypoints=None, func_bounding_boxes='keypoints', func_polygons='keypoints', func_line_strings='keypoints', seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]¶ Bases:
imgaug.augmenters.meta.Augmenter
Augmenter that calls a lambda function for each input batch.
This is useful to add missing functions to a list of augmenters.
Supported dtypes:
uint8
: yes; fully testeduint16
: yes; testeduint32
: yes; testeduint64
: yes; testedint8
: yes; testedint16
: yes; testedint32
: yes; testedint64
: yes; testedfloat16
: yes; testedfloat32
: yes; testedfloat64
: yes; testedfloat128
: yes; testedbool
: yes; tested
Parameters: func_images (None or callable, optional) – The function to call for each batch of images. It must follow the form:
function(images, random_state, parents, hooks)
and return the changed images (may be transformed in-place). This is essentially the interface of
_augment_images()
. If this isNone
instead of a function, the images will not be altered.func_heatmaps (None or callable, optional) – The function to call for each batch of heatmaps. It must follow the form:
function(heatmaps, random_state, parents, hooks)
and return the changed heatmaps (may be transformed in-place). This is essentially the interface of
_augment_heatmaps()
. If this isNone
instead of a function, the heatmaps will not be altered.func_segmentation_maps (None or callable, optional) – The function to call for each batch of segmentation maps. It must follow the form:
function(segmaps, random_state, parents, hooks)
and return the changed segmaps (may be transformed in-place). This is essentially the interface of
_augment_segmentation_maps()
. If this isNone
instead of a function, the segmentatio maps will not be altered.func_keypoints (None or callable, optional) – The function to call for each batch of keypoints. It must follow the form:
function(keypoints_on_images, random_state, parents, hooks)
and return the changed keypoints (may be transformed in-place). This is essentially the interface of
_augment_keypoints()
. If this isNone
instead of a function, the keypoints will not be altered.func_bounding_boxes (“keypoints” or None or callable, optional) – The function to call for each batch of bounding boxes. It must follow the form:
function(bounding_boxes_on_images, random_state, parents, hooks)
and return the changed bounding boxes (may be transformed in-place). This is essentially the interface of
_augment_bounding_boxes()
. If this isNone
instead of a function, the bounding boxes will not be altered. If this is the string"keypoints"
instead of a function, the bounding boxes will automatically be augmented by transforming their corner vertices to keypoints and calling func_keypoints.Added in 0.4.0.
func_polygons (“keypoints” or None or callable, optional) – The function to call for each batch of polygons. It must follow the form:
function(polygons_on_images, random_state, parents, hooks)
and return the changed polygons (may be transformed in-place). This is essentially the interface of
_augment_polygons()
. If this isNone
instead of a function, the polygons will not be altered. If this is the string"keypoints"
instead of a function, the polygons will automatically be augmented by transforming their corner vertices to keypoints and calling func_keypoints.func_line_strings (“keypoints” or None or callable, optional) – The function to call for each batch of line strings. It must follow the form:
function(line_strings_on_images, random_state, parents, hooks)
and return the changed line strings (may be transformed in-place). This is essentially the interface of
_augment_line_strings()
. If this isNone
instead of a function, the line strings will not be altered. If this is the string"keypoints"
instead of a function, the line strings will automatically be augmented by transforming their corner vertices to keypoints and calling func_keypoints.Added in 0.4.0.
seed (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See
__init__()
.name (None or str, optional) – See
__init__()
.random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – Old name for parameter seed. Its usage will not yet cause a deprecation warning, but it is still recommended to use seed now. Outdated since 0.4.0.
deterministic (bool, optional) – Deprecated since 0.4.0. See method
to_deterministic()
for an alternative and for details about what the “deterministic mode” actually does.
Examples
>>> import imgaug.augmenters as iaa >>> >>> def func_images(images, random_state, parents, hooks): >>> images[:, ::2, :, :] = 0 >>> return images >>> >>> aug = iaa.Lambda( >>> func_images=func_images >>> )
Replace every second row in input images with black pixels. Leave other data (e.g. heatmaps, keypoints) unchanged.
>>> def func_images(images, random_state, parents, hooks): >>> images[:, ::2, :, :] = 0 >>> return images >>> >>> def func_heatmaps(heatmaps, random_state, parents, hooks): >>> for heatmaps_i in heatmaps: >>> heatmaps.arr_0to1[::2, :, :] = 0 >>> return heatmaps >>> >>> def func_keypoints(keypoints_on_images, random_state, parents, hooks): >>> return keypoints_on_images >>> >>> aug = iaa.Lambda( >>> func_images=func_images, >>> func_heatmaps=func_heatmaps, >>> func_keypoints=func_keypoints >>> )
Replace every second row in images with black pixels, set every second row in heatmaps to zero and leave other data (e.g. keypoints) unchanged.
Methods
__call__
(self, \*args, \*\*kwargs)Alias for augment()
.augment
(self[, return_batch, hooks])Augment a batch. augment_batch
(self, batch[, hooks])Deprecated. augment_batch_
(self, batch[, parents, hooks])Augment a single batch in-place. augment_batches
(self, batches[, hooks, …])Augment multiple batches. augment_bounding_boxes
(self, …[, parents, …])Augment a batch of bounding boxes. augment_heatmaps
(self, heatmaps[, parents, …])Augment a batch of heatmaps. augment_image
(self, image[, hooks])Augment a single image. augment_images
(self, images[, parents, hooks])Augment a batch of images. augment_keypoints
(self, keypoints_on_images)Augment a batch of keypoints/landmarks. augment_line_strings
(self, …[, parents, hooks])Augment a batch of line strings. augment_polygons
(self, polygons_on_images[, …])Augment a batch of polygons. augment_segmentation_maps
(self, segmaps[, …])Augment a batch of segmentation maps. copy
(self)Create a shallow copy of this Augmenter instance. copy_random_state
(self, source[, recursive, …])Copy the RNGs from a source augmenter sequence. copy_random_state_
(self, source[, …])Copy the RNGs from a source augmenter sequence (in-place). deepcopy
(self)Create a deep copy of this Augmenter instance. draw_grid
(self, images, rows, cols)Augment images and draw the results as a single grid-like image. find_augmenters
(self, func[, parents, flat])Find augmenters that match a condition. find_augmenters_by_name
(self, name[, regex, …])Find augmenter(s) by name. find_augmenters_by_names
(self, names[, …])Find augmenter(s) by names. get_all_children
(self[, flat])Get all children of this augmenter as a list. get_children_lists
(self)Get a list of lists of children of this augmenter. get_parameters
(self)See get_parameters()
.localize_random_state
(self[, recursive])Assign augmenter-specific RNGs to this augmenter and its children. localize_random_state_
(self[, recursive])Assign augmenter-specific RNGs to this augmenter and its children. pool
(self[, processes, maxtasksperchild, seed])Create a pool used for multicore augmentation. remove_augmenters
(self, func[, copy, …])Remove this augmenter or children that match a condition. remove_augmenters_
(self, func[, parents])Remove in-place children of this augmenter that match a condition. remove_augmenters_inplace
(self, func[, parents])Deprecated. reseed
(self[, random_state, deterministic_too])Deprecated. seed_
(self[, entropy, deterministic_too])Seed this augmenter and all of its children. show_grid
(self, images, rows, cols)Augment images and plot the results as a single grid-like image. to_deterministic
(self[, n])Convert this augmenter from a stochastic to a deterministic one. -
get_parameters
(self)[source]¶ See
get_parameters()
.
-
class
imgaug.augmenters.meta.
Noop
(seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]¶ Bases:
imgaug.augmenters.meta.Identity
Alias for augmenter
Identity
.It is recommended to now use
Identity
.Noop
might be deprecated in the future.Supported dtypes:
See
Identity
.Parameters: - seed (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See
__init__()
. - name (None or str, optional) – See
__init__()
. - random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – Old name for parameter seed. Its usage will not yet cause a deprecation warning, but it is still recommended to use seed now. Outdated since 0.4.0.
- deterministic (bool, optional) – Deprecated since 0.4.0.
See method
to_deterministic()
for an alternative and for details about what the “deterministic mode” actually does.
Examples
>>> import imgaug.augmenters as iaa >>> aug = iaa.Noop()
Create an augmenter that does not change inputs.
Methods
__call__
(self, \*args, \*\*kwargs)Alias for augment()
.augment
(self[, return_batch, hooks])Augment a batch. augment_batch
(self, batch[, hooks])Deprecated. augment_batch_
(self, batch[, parents, hooks])Augment a single batch in-place. augment_batches
(self, batches[, hooks, …])Augment multiple batches. augment_bounding_boxes
(self, …[, parents, …])Augment a batch of bounding boxes. augment_heatmaps
(self, heatmaps[, parents, …])Augment a batch of heatmaps. augment_image
(self, image[, hooks])Augment a single image. augment_images
(self, images[, parents, hooks])Augment a batch of images. augment_keypoints
(self, keypoints_on_images)Augment a batch of keypoints/landmarks. augment_line_strings
(self, …[, parents, hooks])Augment a batch of line strings. augment_polygons
(self, polygons_on_images[, …])Augment a batch of polygons. augment_segmentation_maps
(self, segmaps[, …])Augment a batch of segmentation maps. copy
(self)Create a shallow copy of this Augmenter instance. copy_random_state
(self, source[, recursive, …])Copy the RNGs from a source augmenter sequence. copy_random_state_
(self, source[, …])Copy the RNGs from a source augmenter sequence (in-place). deepcopy
(self)Create a deep copy of this Augmenter instance. draw_grid
(self, images, rows, cols)Augment images and draw the results as a single grid-like image. find_augmenters
(self, func[, parents, flat])Find augmenters that match a condition. find_augmenters_by_name
(self, name[, regex, …])Find augmenter(s) by name. find_augmenters_by_names
(self, names[, …])Find augmenter(s) by names. get_all_children
(self[, flat])Get all children of this augmenter as a list. get_children_lists
(self)Get a list of lists of children of this augmenter. get_parameters
(self)See get_parameters()
.localize_random_state
(self[, recursive])Assign augmenter-specific RNGs to this augmenter and its children. localize_random_state_
(self[, recursive])Assign augmenter-specific RNGs to this augmenter and its children. pool
(self[, processes, maxtasksperchild, seed])Create a pool used for multicore augmentation. remove_augmenters
(self, func[, copy, …])Remove this augmenter or children that match a condition. remove_augmenters_
(self, func[, parents])Remove in-place children of this augmenter that match a condition. remove_augmenters_inplace
(self, func[, parents])Deprecated. reseed
(self[, random_state, deterministic_too])Deprecated. seed_
(self[, entropy, deterministic_too])Seed this augmenter and all of its children. show_grid
(self, images, rows, cols)Augment images and plot the results as a single grid-like image. to_deterministic
(self[, n])Convert this augmenter from a stochastic to a deterministic one. - seed (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See
-
class
imgaug.augmenters.meta.
OneOf
(children, seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]¶ Bases:
imgaug.augmenters.meta.SomeOf
Augmenter that always executes exactly one of its children.
Supported dtypes:
See
imgaug.augmenters.meta.SomeOf
.Parameters: - children (imgaug.augmenters.meta.Augmenter or list of imgaug.augmenters.meta.Augmenter) – The choices of augmenters to apply.
- seed (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See
__init__()
. - name (None or str, optional) – See
__init__()
. - random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – Old name for parameter seed. Its usage will not yet cause a deprecation warning, but it is still recommended to use seed now. Outdated since 0.4.0.
- deterministic (bool, optional) – Deprecated since 0.4.0.
See method
to_deterministic()
for an alternative and for details about what the “deterministic mode” actually does.
Examples
>>> import imgaug.augmenters as iaa >>> images = [np.ones((10, 10), dtype=np.uint8)] # dummy example images >>> seq = iaa.OneOf([ >>> iaa.Fliplr(1.0), >>> iaa.Flipud(1.0) >>> ]) >>> images_aug = seq.augment_images(images)
Flip each image either horizontally or vertically.
>>> images = [np.ones((10, 10), dtype=np.uint8)] # dummy example images >>> seq = iaa.OneOf([ >>> iaa.Fliplr(1.0), >>> iaa.Sequential([ >>> iaa.GaussianBlur(1.0), >>> iaa.Dropout(0.05), >>> iaa.AdditiveGaussianNoise(0.1*255) >>> ]), >>> iaa.Noop() >>> ]) >>> images_aug = seq.augment_images(images)
Either flip each image horizontally, or add blur+dropout+noise or do nothing.
Methods
__call__
(self, \*args, \*\*kwargs)Alias for augment()
.add
(self, augmenter)Add an augmenter to the list of child augmenters. append
(self, object, /)Append object to the end of the list. augment
(self[, return_batch, hooks])Augment a batch. augment_batch
(self, batch[, hooks])Deprecated. augment_batch_
(self, batch[, parents, hooks])Augment a single batch in-place. augment_batches
(self, batches[, hooks, …])Augment multiple batches. augment_bounding_boxes
(self, …[, parents, …])Augment a batch of bounding boxes. augment_heatmaps
(self, heatmaps[, parents, …])Augment a batch of heatmaps. augment_image
(self, image[, hooks])Augment a single image. augment_images
(self, images[, parents, hooks])Augment a batch of images. augment_keypoints
(self, keypoints_on_images)Augment a batch of keypoints/landmarks. augment_line_strings
(self, …[, parents, hooks])Augment a batch of line strings. augment_polygons
(self, polygons_on_images[, …])Augment a batch of polygons. augment_segmentation_maps
(self, segmaps[, …])Augment a batch of segmentation maps. clear
(self, /)Remove all items from list. copy
(self)Create a shallow copy of this Augmenter instance. copy_random_state
(self, source[, recursive, …])Copy the RNGs from a source augmenter sequence. copy_random_state_
(self, source[, …])Copy the RNGs from a source augmenter sequence (in-place). count
(self, value, /)Return number of occurrences of value. deepcopy
(self)Create a deep copy of this Augmenter instance. draw_grid
(self, images, rows, cols)Augment images and draw the results as a single grid-like image. extend
(self, iterable, /)Extend list by appending elements from the iterable. find_augmenters
(self, func[, parents, flat])Find augmenters that match a condition. find_augmenters_by_name
(self, name[, regex, …])Find augmenter(s) by name. find_augmenters_by_names
(self, names[, …])Find augmenter(s) by names. get_all_children
(self[, flat])Get all children of this augmenter as a list. get_children_lists
(self)See get_children_lists()
.get_parameters
(self)See get_parameters()
.index
(self, value[, start, stop])Return first index of value. insert
(self, index, object, /)Insert object before index. localize_random_state
(self[, recursive])Assign augmenter-specific RNGs to this augmenter and its children. localize_random_state_
(self[, recursive])Assign augmenter-specific RNGs to this augmenter and its children. pool
(self[, processes, maxtasksperchild, seed])Create a pool used for multicore augmentation. pop
(self[, index])Remove and return item at index (default last). remove
(self, value, /)Remove first occurrence of value. remove_augmenters
(self, func[, copy, …])Remove this augmenter or children that match a condition. remove_augmenters_
(self, func[, parents])Remove in-place children of this augmenter that match a condition. remove_augmenters_inplace
(self, func[, parents])Deprecated. reseed
(self[, random_state, deterministic_too])Deprecated. reverse
(self, /)Reverse IN PLACE. seed_
(self[, entropy, deterministic_too])Seed this augmenter and all of its children. show_grid
(self, images, rows, cols)Augment images and plot the results as a single grid-like image. sort
(self, /, \*[, key, reverse])Stable sort IN PLACE. to_deterministic
(self[, n])Convert this augmenter from a stochastic to a deterministic one.
-
class
imgaug.augmenters.meta.
RemoveCBAsByOutOfImageFraction
(fraction, seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]¶ Bases:
imgaug.augmenters.meta.Augmenter
Remove coordinate-based augmentables exceeding an out of image fraction.
This augmenter inspects all coordinate-based augmentables (e.g. bounding boxes, line strings) within a given batch and removes any such augmentable which’s out of image fraction is exactly a given value or greater than that. The out of image fraction denotes the fraction of the augmentable’s area that is outside of the image, e.g. for a bounding box that has half of its area outside of the image it would be
0.5
.Added in 0.4.0.
Supported dtypes:
uint8
: yes; fully testeduint16
: yes; fully testeduint32
: yes; fully testeduint64
: yes; fully testedint8
: yes; fully testedint16
: yes; fully testedint32
: yes; fully testedint64
: yes; fully testedfloat16
: yes; fully testedfloat32
: yes; fully testedfloat64
: yes; fully testedfloat128
: yes; fully testedbool
: yes; fully tested
Parameters: - fraction (number) – Remove any augmentable for which
fraction_{actual} >= fraction
, wherefraction_{actual}
denotes the estimated out of image fraction. - seed (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See
__init__()
. - name (None or str, optional) – See
__init__()
. - random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – Old name for parameter seed. Its usage will not yet cause a deprecation warning, but it is still recommended to use seed now. Outdated since 0.4.0.
- deterministic (bool, optional) – Deprecated since 0.4.0.
See method
to_deterministic()
for an alternative and for details about what the “deterministic mode” actually does.
Examples
>>> import imgaug.augmenters as iaa >>> aug = iaa.Sequential([ >>> iaa.Affine(translate_px={"x": (-100, 100)}), >>> iaa.RemoveCBAsByOutOfImageFraction(0.5) >>> ])
Translate all inputs by
-100
to100
pixels on the x-axis, then remove any coordinate-based augmentable (e.g. bounding boxes) which has at least50%
of its area outside of the image plane.>>> import imgaug as ia >>> import imgaug.augmenters as iaa >>> image = ia.quokka_square((100, 100)) >>> bb = ia.BoundingBox(x1=50-25, y1=0, x2=50+25, y2=100) >>> bbsoi = ia.BoundingBoxesOnImage([bb], shape=image.shape) >>> aug_without = iaa.Affine(translate_px={"x": 51}) >>> aug_with = iaa.Sequential([ >>> iaa.Affine(translate_px={"x": 51}), >>> iaa.RemoveCBAsByOutOfImageFraction(0.5) >>> ]) >>> >>> image_without, bbsoi_without = aug_without( >>> image=image, bounding_boxes=bbsoi) >>> image_with, bbsoi_with = aug_with( >>> image=image, bounding_boxes=bbsoi) >>> >>> assert len(bbsoi_without.bounding_boxes) == 1 >>> assert len(bbsoi_with.bounding_boxes) == 0
Create a bounding box on an example image, then translate the image so that
50%
of the bounding box’s area is outside of the image and compare the effects and usingRemoveCBAsByOutOfImageFraction
with not using it.Methods
__call__
(self, \*args, \*\*kwargs)Alias for augment()
.augment
(self[, return_batch, hooks])Augment a batch. augment_batch
(self, batch[, hooks])Deprecated. augment_batch_
(self, batch[, parents, hooks])Augment a single batch in-place. augment_batches
(self, batches[, hooks, …])Augment multiple batches. augment_bounding_boxes
(self, …[, parents, …])Augment a batch of bounding boxes. augment_heatmaps
(self, heatmaps[, parents, …])Augment a batch of heatmaps. augment_image
(self, image[, hooks])Augment a single image. augment_images
(self, images[, parents, hooks])Augment a batch of images. augment_keypoints
(self, keypoints_on_images)Augment a batch of keypoints/landmarks. augment_line_strings
(self, …[, parents, hooks])Augment a batch of line strings. augment_polygons
(self, polygons_on_images[, …])Augment a batch of polygons. augment_segmentation_maps
(self, segmaps[, …])Augment a batch of segmentation maps. copy
(self)Create a shallow copy of this Augmenter instance. copy_random_state
(self, source[, recursive, …])Copy the RNGs from a source augmenter sequence. copy_random_state_
(self, source[, …])Copy the RNGs from a source augmenter sequence (in-place). deepcopy
(self)Create a deep copy of this Augmenter instance. draw_grid
(self, images, rows, cols)Augment images and draw the results as a single grid-like image. find_augmenters
(self, func[, parents, flat])Find augmenters that match a condition. find_augmenters_by_name
(self, name[, regex, …])Find augmenter(s) by name. find_augmenters_by_names
(self, names[, …])Find augmenter(s) by names. get_all_children
(self[, flat])Get all children of this augmenter as a list. get_children_lists
(self)Get a list of lists of children of this augmenter. get_parameters
(self)See get_parameters()
.localize_random_state
(self[, recursive])Assign augmenter-specific RNGs to this augmenter and its children. localize_random_state_
(self[, recursive])Assign augmenter-specific RNGs to this augmenter and its children. pool
(self[, processes, maxtasksperchild, seed])Create a pool used for multicore augmentation. remove_augmenters
(self, func[, copy, …])Remove this augmenter or children that match a condition. remove_augmenters_
(self, func[, parents])Remove in-place children of this augmenter that match a condition. remove_augmenters_inplace
(self, func[, parents])Deprecated. reseed
(self[, random_state, deterministic_too])Deprecated. seed_
(self[, entropy, deterministic_too])Seed this augmenter and all of its children. show_grid
(self, images, rows, cols)Augment images and plot the results as a single grid-like image. to_deterministic
(self[, n])Convert this augmenter from a stochastic to a deterministic one. -
get_parameters
(self)[source]¶ See
get_parameters()
.
-
class
imgaug.augmenters.meta.
Sequential
(children=None, random_order=False, seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]¶ Bases:
imgaug.augmenters.meta.Augmenter
,list
List augmenter containing child augmenters to apply to inputs.
This augmenter is simply a list of other augmenters. To augment an image or any other data, it iterates over its children and applies each one of them independently to the data. (This also means that the second applied augmenter will already receive augmented input data and augment it further.)
This augmenter offers the option to apply its children in random order using the random_order parameter. This should often be activated as it greatly increases the space of possible augmentations.
Note
You are not forced to use
Sequential
in order to use other augmenters. Each augmenter can be used on its own, e.g the following defines an augmenter for horizontal flips and then augments a single image:>>> import numpy as np >>> import imgaug.augmenters as iaa >>> image = np.zeros((32, 32, 3), dtype=np.uint8) >>> aug = iaa.Fliplr(0.5) >>> image_aug = aug.augment_image(image)
Supported dtypes:
uint8
: yes; fully testeduint16
: yes; testeduint32
: yes; testeduint64
: yes; testedint8
: yes; testedint16
: yes; testedint32
: yes; testedint64
: yes; testedfloat16
: yes; testedfloat32
: yes; testedfloat64
: yes; testedfloat128
: yes; testedbool
: yes; tested
Parameters: - children (imgaug.augmenters.meta.Augmenter or list of imgaug.augmenters.meta.Augmenter or None, optional) – The augmenters to apply to images.
- random_order (bool, optional) – Whether to apply the child augmenters in random order.
If
True
, the order will be randomly sampled once per batch. - seed (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See
__init__()
. - name (None or str, optional) – See
__init__()
. - random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – Old name for parameter seed. Its usage will not yet cause a deprecation warning, but it is still recommended to use seed now. Outdated since 0.4.0.
- deterministic (bool, optional) – Deprecated since 0.4.0.
See method
to_deterministic()
for an alternative and for details about what the “deterministic mode” actually does.
Examples
>>> import numpy as np >>> import imgaug.augmenters as iaa >>> imgs = [np.random.rand(10, 10)] >>> seq = iaa.Sequential([ >>> iaa.Fliplr(0.5), >>> iaa.Flipud(0.5) >>> ]) >>> imgs_aug = seq.augment_images(imgs)
Create a
Sequential
that always first applies a horizontal flip augmenter and then a vertical flip augmenter. Each of these two augmenters has a50%
probability of actually flipping the image.>>> seq = iaa.Sequential([ >>> iaa.Fliplr(0.5), >>> iaa.Flipud(0.5) >>> ], random_order=True) >>> imgs_aug = seq.augment_images(imgs)
Create a
Sequential
that sometimes first applies a horizontal flip augmenter (followed by a vertical flip augmenter) and sometimes first a vertical flip augmenter (followed by a horizontal flip augmenter). Again, each of them has a50%
probability of actually flipping the image.Methods
__call__
(self, \*args, \*\*kwargs)Alias for augment()
.add
(self, augmenter)Add an augmenter to the list of child augmenters. append
(self, object, /)Append object to the end of the list. augment
(self[, return_batch, hooks])Augment a batch. augment_batch
(self, batch[, hooks])Deprecated. augment_batch_
(self, batch[, parents, hooks])Augment a single batch in-place. augment_batches
(self, batches[, hooks, …])Augment multiple batches. augment_bounding_boxes
(self, …[, parents, …])Augment a batch of bounding boxes. augment_heatmaps
(self, heatmaps[, parents, …])Augment a batch of heatmaps. augment_image
(self, image[, hooks])Augment a single image. augment_images
(self, images[, parents, hooks])Augment a batch of images. augment_keypoints
(self, keypoints_on_images)Augment a batch of keypoints/landmarks. augment_line_strings
(self, …[, parents, hooks])Augment a batch of line strings. augment_polygons
(self, polygons_on_images[, …])Augment a batch of polygons. augment_segmentation_maps
(self, segmaps[, …])Augment a batch of segmentation maps. clear
(self, /)Remove all items from list. copy
(self)Create a shallow copy of this Augmenter instance. copy_random_state
(self, source[, recursive, …])Copy the RNGs from a source augmenter sequence. copy_random_state_
(self, source[, …])Copy the RNGs from a source augmenter sequence (in-place). count
(self, value, /)Return number of occurrences of value. deepcopy
(self)Create a deep copy of this Augmenter instance. draw_grid
(self, images, rows, cols)Augment images and draw the results as a single grid-like image. extend
(self, iterable, /)Extend list by appending elements from the iterable. find_augmenters
(self, func[, parents, flat])Find augmenters that match a condition. find_augmenters_by_name
(self, name[, regex, …])Find augmenter(s) by name. find_augmenters_by_names
(self, names[, …])Find augmenter(s) by names. get_all_children
(self[, flat])Get all children of this augmenter as a list. get_children_lists
(self)See get_children_lists()
.get_parameters
(self)See get_parameters()
.index
(self, value[, start, stop])Return first index of value. insert
(self, index, object, /)Insert object before index. localize_random_state
(self[, recursive])Assign augmenter-specific RNGs to this augmenter and its children. localize_random_state_
(self[, recursive])Assign augmenter-specific RNGs to this augmenter and its children. pool
(self[, processes, maxtasksperchild, seed])Create a pool used for multicore augmentation. pop
(self[, index])Remove and return item at index (default last). remove
(self, value, /)Remove first occurrence of value. remove_augmenters
(self, func[, copy, …])Remove this augmenter or children that match a condition. remove_augmenters_
(self, func[, parents])Remove in-place children of this augmenter that match a condition. remove_augmenters_inplace
(self, func[, parents])Deprecated. reseed
(self[, random_state, deterministic_too])Deprecated. reverse
(self, /)Reverse IN PLACE. seed_
(self[, entropy, deterministic_too])Seed this augmenter and all of its children. show_grid
(self, images, rows, cols)Augment images and plot the results as a single grid-like image. sort
(self, /, \*[, key, reverse])Stable sort IN PLACE. to_deterministic
(self[, n])Convert this augmenter from a stochastic to a deterministic one. -
add
(self, augmenter)[source]¶ Add an augmenter to the list of child augmenters.
Parameters: imgaug.augmenters.meta.Augmenter – The augmenter to add.
-
get_children_lists
(self)[source]¶ See
get_children_lists()
.
-
get_parameters
(self)[source]¶ See
get_parameters()
.
-
class
imgaug.augmenters.meta.
SomeOf
(n=None, children=None, random_order=False, seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]¶ Bases:
imgaug.augmenters.meta.Augmenter
,list
List augmenter that applies only some of its children to inputs.
This augmenter is similar to
Sequential
, but may apply only a fixed or random subset of its child augmenters to inputs. E.g. the augmenter could be initialized with a list of 20 child augmenters and then apply 5 randomly chosen child augmenters to images.The subset of augmenters to apply (and their order) is sampled once per image. If random_order is
True
, the order will be sampled once per batch (similar toSequential
).This augmenter currently does not support replacing (i.e. picking the same child multiple times) due to implementation difficulties in connection with deterministic augmenters.
Supported dtypes:
uint8
: yes; fully testeduint16
: yes; testeduint32
: yes; testeduint64
: yes; testedint8
: yes; testedint16
: yes; testedint32
: yes; testedint64
: yes; testedfloat16
: yes; testedfloat32
: yes; testedfloat64
: yes; testedfloat128
: yes; testedbool
: yes; tested
Parameters: n (int or tuple of int or list of int or imgaug.parameters.StochasticParameter or None, optional) –
Count of augmenters to apply.
- If
int
, then exactly n of the child augmenters are applied to every image. - If tuple of two
int
s(a, b)
, then a random value will be uniformly sampled per image from the discrete interval[a..b]
and denote the number of child augmenters to pick and apply.b
may be set toNone
, which is then equivalent to(a..C)
withC
denoting the number of children that the augmenter has. - If
StochasticParameter
, thenN
numbers will be sampled forN
images. The parameter is expected to be discrete. - If
None
, then the total number of available children will be used (i.e. all children will be applied).
- If
children (imgaug.augmenters.meta.Augmenter or list of imgaug.augmenters.meta.Augmenter or None, optional) – The augmenters to apply to images. If this is a list of augmenters, it will be converted to a
Sequential
.random_order (boolean, optional) – Whether to apply the child augmenters in random order. If
True
, the order will be randomly sampled once per batch.seed (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See
__init__()
.name (None or str, optional) – See
__init__()
.random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – Old name for parameter seed. Its usage will not yet cause a deprecation warning, but it is still recommended to use seed now. Outdated since 0.4.0.
deterministic (bool, optional) – Deprecated since 0.4.0. See method
to_deterministic()
for an alternative and for details about what the “deterministic mode” actually does.
Examples
>>> import imgaug.augmenters as iaa >>> imgs = [np.random.rand(10, 10)] >>> seq = iaa.SomeOf(1, [ >>> iaa.Fliplr(1.0), >>> iaa.Flipud(1.0) >>> ]) >>> imgs_aug = seq.augment_images(imgs)
Apply either
Fliplr
orFlipud
to images.>>> seq = iaa.SomeOf((1, 3), [ >>> iaa.Fliplr(1.0), >>> iaa.Flipud(1.0), >>> iaa.GaussianBlur(1.0) >>> ]) >>> imgs_aug = seq.augment_images(imgs)
Apply one to three of the listed augmenters (
Fliplr
,Flipud
,GaussianBlur
) to images. They are always applied in the provided order, i.e. firstFliplr
, secondFlipud
, thirdGaussianBlur
.>>> seq = iaa.SomeOf((1, None), [ >>> iaa.Fliplr(1.0), >>> iaa.Flipud(1.0), >>> iaa.GaussianBlur(1.0) >>> ], random_order=True) >>> imgs_aug = seq.augment_images(imgs)
Apply one to all of the listed augmenters (
Fliplr
,Flipud
,GaussianBlur
) to images. They are applied in random order, i.e. sometimesGaussianBlur
first, followed byFliplr
, sometimesFliplr
followed byFlipud
followed byBlur
etc. The order is sampled once per batch.Methods
__call__
(self, \*args, \*\*kwargs)Alias for augment()
.add
(self, augmenter)Add an augmenter to the list of child augmenters. append
(self, object, /)Append object to the end of the list. augment
(self[, return_batch, hooks])Augment a batch. augment_batch
(self, batch[, hooks])Deprecated. augment_batch_
(self, batch[, parents, hooks])Augment a single batch in-place. augment_batches
(self, batches[, hooks, …])Augment multiple batches. augment_bounding_boxes
(self, …[, parents, …])Augment a batch of bounding boxes. augment_heatmaps
(self, heatmaps[, parents, …])Augment a batch of heatmaps. augment_image
(self, image[, hooks])Augment a single image. augment_images
(self, images[, parents, hooks])Augment a batch of images. augment_keypoints
(self, keypoints_on_images)Augment a batch of keypoints/landmarks. augment_line_strings
(self, …[, parents, hooks])Augment a batch of line strings. augment_polygons
(self, polygons_on_images[, …])Augment a batch of polygons. augment_segmentation_maps
(self, segmaps[, …])Augment a batch of segmentation maps. clear
(self, /)Remove all items from list. copy
(self)Create a shallow copy of this Augmenter instance. copy_random_state
(self, source[, recursive, …])Copy the RNGs from a source augmenter sequence. copy_random_state_
(self, source[, …])Copy the RNGs from a source augmenter sequence (in-place). count
(self, value, /)Return number of occurrences of value. deepcopy
(self)Create a deep copy of this Augmenter instance. draw_grid
(self, images, rows, cols)Augment images and draw the results as a single grid-like image. extend
(self, iterable, /)Extend list by appending elements from the iterable. find_augmenters
(self, func[, parents, flat])Find augmenters that match a condition. find_augmenters_by_name
(self, name[, regex, …])Find augmenter(s) by name. find_augmenters_by_names
(self, names[, …])Find augmenter(s) by names. get_all_children
(self[, flat])Get all children of this augmenter as a list. get_children_lists
(self)See get_children_lists()
.get_parameters
(self)See get_parameters()
.index
(self, value[, start, stop])Return first index of value. insert
(self, index, object, /)Insert object before index. localize_random_state
(self[, recursive])Assign augmenter-specific RNGs to this augmenter and its children. localize_random_state_
(self[, recursive])Assign augmenter-specific RNGs to this augmenter and its children. pool
(self[, processes, maxtasksperchild, seed])Create a pool used for multicore augmentation. pop
(self[, index])Remove and return item at index (default last). remove
(self, value, /)Remove first occurrence of value. remove_augmenters
(self, func[, copy, …])Remove this augmenter or children that match a condition. remove_augmenters_
(self, func[, parents])Remove in-place children of this augmenter that match a condition. remove_augmenters_inplace
(self, func[, parents])Deprecated. reseed
(self[, random_state, deterministic_too])Deprecated. reverse
(self, /)Reverse IN PLACE. seed_
(self[, entropy, deterministic_too])Seed this augmenter and all of its children. show_grid
(self, images, rows, cols)Augment images and plot the results as a single grid-like image. sort
(self, /, \*[, key, reverse])Stable sort IN PLACE. to_deterministic
(self[, n])Convert this augmenter from a stochastic to a deterministic one. -
add
(self, augmenter)[source]¶ Add an augmenter to the list of child augmenters.
Parameters: augmenter (imgaug.augmenters.meta.Augmenter) – The augmenter to add.
-
get_children_lists
(self)[source]¶ See
get_children_lists()
.
-
get_parameters
(self)[source]¶ See
get_parameters()
.
-
class
imgaug.augmenters.meta.
Sometimes
(p=0.5, then_list=None, else_list=None, seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]¶ Bases:
imgaug.augmenters.meta.Augmenter
Apply child augmenter(s) with a probability of p.
Let
C
be one or more child augmenters given toSometimes
. Letp
be the fraction of images (or other data) to augment. LetI
be the input images (or other data). LetN
be the number of input images (or other entities). Then (on average)p*N
images ofI
will be augmented usingC
.Supported dtypes:
uint8
: yes; fully testeduint16
: yes; testeduint32
: yes; testeduint64
: yes; testedint8
: yes; testedint16
: yes; testedint32
: yes; testedint64
: yes; testedfloat16
: yes; testedfloat32
: yes; testedfloat64
: yes; testedfloat128
: yes; testedbool
: yes; tested
Parameters: - p (float or imgaug.parameters.StochasticParameter, optional) – Sets the probability with which the given augmenters will be applied to
input images/data. E.g. a value of
0.5
will result in50%
of all input images (or other augmentables) being augmented. - then_list (None or imgaug.augmenters.meta.Augmenter or list of imgaug.augmenters.meta.Augmenter, optional) – Augmenter(s) to apply to p% percent of all images.
If this is a list of augmenters, it will be converted to a
Sequential
. - else_list (None or imgaug.augmenters.meta.Augmenter or list of imgaug.augmenters.meta.Augmenter, optional) – Augmenter(s) to apply to
(1-p)
percent of all images. These augmenters will be applied only when the ones in then_list are not applied (either-or-relationship). If this is a list of augmenters, it will be converted to aSequential
. - seed (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See
__init__()
. - name (None or str, optional) – See
__init__()
. - random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – Old name for parameter seed. Its usage will not yet cause a deprecation warning, but it is still recommended to use seed now. Outdated since 0.4.0.
- deterministic (bool, optional) – Deprecated since 0.4.0.
See method
to_deterministic()
for an alternative and for details about what the “deterministic mode” actually does.
Examples
>>> import imgaug.augmenters as iaa >>> aug = iaa.Sometimes(0.5, iaa.GaussianBlur(0.3))
Apply
GaussianBlur
to50%
of all input images.>>> aug = iaa.Sometimes(0.5, iaa.GaussianBlur(0.3), iaa.Fliplr(1.0))
Apply
GaussianBlur
to50%
of all input images. ApplyFliplr
to the other50%
of all input images.Methods
__call__
(self, \*args, \*\*kwargs)Alias for augment()
.augment
(self[, return_batch, hooks])Augment a batch. augment_batch
(self, batch[, hooks])Deprecated. augment_batch_
(self, batch[, parents, hooks])Augment a single batch in-place. augment_batches
(self, batches[, hooks, …])Augment multiple batches. augment_bounding_boxes
(self, …[, parents, …])Augment a batch of bounding boxes. augment_heatmaps
(self, heatmaps[, parents, …])Augment a batch of heatmaps. augment_image
(self, image[, hooks])Augment a single image. augment_images
(self, images[, parents, hooks])Augment a batch of images. augment_keypoints
(self, keypoints_on_images)Augment a batch of keypoints/landmarks. augment_line_strings
(self, …[, parents, hooks])Augment a batch of line strings. augment_polygons
(self, polygons_on_images[, …])Augment a batch of polygons. augment_segmentation_maps
(self, segmaps[, …])Augment a batch of segmentation maps. copy
(self)Create a shallow copy of this Augmenter instance. copy_random_state
(self, source[, recursive, …])Copy the RNGs from a source augmenter sequence. copy_random_state_
(self, source[, …])Copy the RNGs from a source augmenter sequence (in-place). deepcopy
(self)Create a deep copy of this Augmenter instance. draw_grid
(self, images, rows, cols)Augment images and draw the results as a single grid-like image. find_augmenters
(self, func[, parents, flat])Find augmenters that match a condition. find_augmenters_by_name
(self, name[, regex, …])Find augmenter(s) by name. find_augmenters_by_names
(self, names[, …])Find augmenter(s) by names. get_all_children
(self[, flat])Get all children of this augmenter as a list. get_children_lists
(self)See get_children_lists()
.get_parameters
(self)See get_parameters()
.localize_random_state
(self[, recursive])Assign augmenter-specific RNGs to this augmenter and its children. localize_random_state_
(self[, recursive])Assign augmenter-specific RNGs to this augmenter and its children. pool
(self[, processes, maxtasksperchild, seed])Create a pool used for multicore augmentation. remove_augmenters
(self, func[, copy, …])Remove this augmenter or children that match a condition. remove_augmenters_
(self, func[, parents])Remove in-place children of this augmenter that match a condition. remove_augmenters_inplace
(self, func[, parents])Deprecated. reseed
(self[, random_state, deterministic_too])Deprecated. seed_
(self[, entropy, deterministic_too])Seed this augmenter and all of its children. show_grid
(self, images, rows, cols)Augment images and plot the results as a single grid-like image. to_deterministic
(self[, n])Convert this augmenter from a stochastic to a deterministic one. -
get_children_lists
(self)[source]¶ See
get_children_lists()
.
-
get_parameters
(self)[source]¶ See
get_parameters()
.
-
class
imgaug.augmenters.meta.
WithChannels
(channels=None, children=None, seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]¶ Bases:
imgaug.augmenters.meta.Augmenter
Apply child augmenters to specific channels.
Let
C
be one or more child augmenters given to this augmenter. LetH
be a list of channels. LetI
be the input images. Then this augmenter will pick the channelsH
from each image inI
(resulting in new images) and applyC
to them. The result of the augmentation will be merged back into the original images.Supported dtypes:
uint8
: yes; fully testeduint16
: yes; testeduint32
: yes; testeduint64
: yes; testedint8
: yes; testedint16
: yes; testedint32
: yes; testedint64
: yes; testedfloat16
: yes; testedfloat32
: yes; testedfloat64
: yes; testedfloat128
: yes; testedbool
: yes; tested
Parameters: - channels (None or int or list of int, optional) – Sets the channels to be extracted from each image.
If
None
, all channels will be used. Note that this is not stochastic - the extracted channels are always the same ones. - children (imgaug.augmenters.meta.Augmenter or list of imgaug.augmenters.meta.Augmenter or None, optional) – One or more augmenters to apply to images, after the channels are extracted.
- seed (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See
__init__()
. - name (None or str, optional) – See
__init__()
. - random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – Old name for parameter seed. Its usage will not yet cause a deprecation warning, but it is still recommended to use seed now. Outdated since 0.4.0.
- deterministic (bool, optional) – Deprecated since 0.4.0.
See method
to_deterministic()
for an alternative and for details about what the “deterministic mode” actually does.
Examples
>>> import imgaug.augmenters as iaa >>> aug = iaa.WithChannels([0], iaa.Add(10))
Assuming input images are RGB, then this augmenter will add
10
only to the first channel, i.e. it will make images appear more red.Methods
__call__
(self, \*args, \*\*kwargs)Alias for augment()
.augment
(self[, return_batch, hooks])Augment a batch. augment_batch
(self, batch[, hooks])Deprecated. augment_batch_
(self, batch[, parents, hooks])Augment a single batch in-place. augment_batches
(self, batches[, hooks, …])Augment multiple batches. augment_bounding_boxes
(self, …[, parents, …])Augment a batch of bounding boxes. augment_heatmaps
(self, heatmaps[, parents, …])Augment a batch of heatmaps. augment_image
(self, image[, hooks])Augment a single image. augment_images
(self, images[, parents, hooks])Augment a batch of images. augment_keypoints
(self, keypoints_on_images)Augment a batch of keypoints/landmarks. augment_line_strings
(self, …[, parents, hooks])Augment a batch of line strings. augment_polygons
(self, polygons_on_images[, …])Augment a batch of polygons. augment_segmentation_maps
(self, segmaps[, …])Augment a batch of segmentation maps. copy
(self)Create a shallow copy of this Augmenter instance. copy_random_state
(self, source[, recursive, …])Copy the RNGs from a source augmenter sequence. copy_random_state_
(self, source[, …])Copy the RNGs from a source augmenter sequence (in-place). deepcopy
(self)Create a deep copy of this Augmenter instance. draw_grid
(self, images, rows, cols)Augment images and draw the results as a single grid-like image. find_augmenters
(self, func[, parents, flat])Find augmenters that match a condition. find_augmenters_by_name
(self, name[, regex, …])Find augmenter(s) by name. find_augmenters_by_names
(self, names[, …])Find augmenter(s) by names. get_all_children
(self[, flat])Get all children of this augmenter as a list. get_children_lists
(self)See get_children_lists()
.get_parameters
(self)See get_parameters()
.localize_random_state
(self[, recursive])Assign augmenter-specific RNGs to this augmenter and its children. localize_random_state_
(self[, recursive])Assign augmenter-specific RNGs to this augmenter and its children. pool
(self[, processes, maxtasksperchild, seed])Create a pool used for multicore augmentation. remove_augmenters
(self, func[, copy, …])Remove this augmenter or children that match a condition. remove_augmenters_
(self, func[, parents])Remove in-place children of this augmenter that match a condition. remove_augmenters_inplace
(self, func[, parents])Deprecated. reseed
(self[, random_state, deterministic_too])Deprecated. seed_
(self[, entropy, deterministic_too])Seed this augmenter and all of its children. show_grid
(self, images, rows, cols)Augment images and plot the results as a single grid-like image. to_deterministic
(self[, n])Convert this augmenter from a stochastic to a deterministic one. -
get_children_lists
(self)[source]¶ See
get_children_lists()
.
-
get_parameters
(self)[source]¶ See
get_parameters()
.
-
imgaug.augmenters.meta.
clip_augmented_image
(image, min_value, max_value)[source]¶ Deprecated. Use
imgaug.dtypes.clip_
instead.Clip image.
-
imgaug.augmenters.meta.
clip_augmented_image_
(image, min_value, max_value)[source]¶ Deprecated. Use
imgaug.dtypes.clip_
instead.Clip image in-place.
-
imgaug.augmenters.meta.
clip_augmented_images
(images, min_value, max_value)[source]¶ Deprecated. Use
imgaug.dtypes.clip_
instead.Clip images.
-
imgaug.augmenters.meta.
clip_augmented_images_
(images, min_value, max_value)[source]¶ Deprecated. Use
imgaug.dtypes.clip_
instead.Clip images in-place.
-
imgaug.augmenters.meta.
copy_arrays
(arrays)[source]¶ Copy the arrays of a single input array or list of input arrays.
-
imgaug.augmenters.meta.
estimate_max_number_of_channels
(images)[source]¶ Compute the maximum number of image channels among a list of images.
-
imgaug.augmenters.meta.
handle_children_list
(lst, augmenter_name, lst_name, default='sequential')[source]¶ Normalize an augmenter list provided by a user.
-
imgaug.augmenters.meta.
invert_reduce_to_nonempty
(objs, ids, objs_reduced)[source]¶ Inverse of
reduce_to_nonempty()
.
-
imgaug.augmenters.meta.
reduce_to_nonempty
(objs)[source]¶ Remove from a list all objects that don’t follow
obj.empty==True
.
-
imgaug.augmenters.meta.
shuffle_channels
(image, random_state, channels=None)[source]¶ Randomize the order of (color) channels in an image.
Supported dtypes:
uint8
: yes; fully testeduint16
: yes; indirectly tested (1)uint32
: yes; indirectly tested (1)uint64
: yes; indirectly tested (1)int8
: yes; indirectly tested (1)int16
: yes; indirectly tested (1)int32
: yes; indirectly tested (1)int64
: yes; indirectly tested (1)float16
: yes; indirectly tested (1)float32
: yes; indirectly tested (1)float64
: yes; indirectly tested (1)float128
: yes; indirectly tested (1)bool
: yes; indirectly tested (1)
- Indirectly tested via
ChannelShuffle
.
- Indirectly tested via
Parameters: - image ((H,W,[C]) ndarray) – Image of any dtype for which to shuffle the channels.
- random_state (imgaug.random.RNG) – The random state to use for this shuffling operation.
- channels (None or imgaug.ALL or list of int, optional) – Which channels are allowed to be shuffled with each other.
If this is
None
orimgaug.ALL
, then all channels may be shuffled. If it is alist
ofint
s, then only the channels with indices in that list may be shuffled. (Values start at0
. All channel indices in the list must exist in the image.)
Returns: The input image with shuffled channels.
Return type: ndarray