Augmentor
Augmentor: An Image Augmentation Library for Machine Learning - Published in JOSS (2017)
Science Score: 95.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
✓DOI references
Found 1 DOI reference(s) in JOSS metadata -
○Academic publication links
-
✓Committers with academic emails
1 of 23 committers (4.3%) from academic institutions -
○Institutional organization owner
-
✓JOSS paper metadata
Published in Journal of Open Source Software
Keywords
Scientific Fields
Repository
Image augmentation library in Python for machine learning.
Basic Info
- Host: GitHub
- Owner: mdbloice
- License: mit
- Language: Python
- Default Branch: master
- Homepage: https://augmentor.readthedocs.io/en/stable
- Size: 1.51 MB
Statistics
- Stars: 5,132
- Watchers: 122
- Forks: 872
- Open Issues: 141
- Releases: 0
Topics
Metadata Files
README.md

Augmentor is an image augmentation library in Python for machine learning. It aims to be a standalone library that is platform and framework independent, which is more convenient, allows for finer grained control over augmentation, and implements the most real-world relevant augmentation techniques. It employs a stochastic approach using building blocks that allow for operations to be pieced together in a pipeline.
Installation
Augmentor is written in Python. A Julia version of the package is also being developed as a sister project and is available here.
Install using pip from the command line:
python
pip install Augmentor
See the documentation for building from source. To upgrade from a previous version, use pip install Augmentor --upgrade.
Documentation
Complete documentation can be found on Read the Docs: https://augmentor.readthedocs.io
Quick Start Guide and Usage
The purpose of Augmentor is to automate image augmentation (artificial data generation) in order to expand datasets as input for machine learning algorithms, especially neural networks and deep learning.
The package works by building an augmentation pipeline where you define a series of operations to perform on a set of images. Operations, such as rotations or transforms, are added one by one to create an augmentation pipeline: when complete, the pipeline can be executed and an augmented dataset is created.
To begin, instantiate a Pipeline object that points to a directory on your file system:
python
import Augmentor
p = Augmentor.Pipeline("/path/to/images")
You can then add operations to the Pipeline object p as follows:
python
p.rotate(probability=0.7, max_left_rotation=10, max_right_rotation=10)
p.zoom(probability=0.5, min_factor=1.1, max_factor=1.5)
Every function requires you to specify a probability, which is used to decide if an operation is applied to an image as it is passed through the augmentation pipeline.
Once you have created a pipeline, you can sample from it like so:
python
p.sample(10000)
which will generate 10,000 augmented images based on your specifications. By default these will be written to the disk in a directory named output relative to the path specified when initialising the p pipeline object above.
If you wish to process each image in the pipeline exactly once, use process():
python
p.process()
This function might be useful for resizing a dataset for example. It would make sense to create a pipeline where all of its operations have their probability set to 1 when using the process() method.
Multi-threading
Augmentor (version >=0.2.1) now uses multi-threading to increase the speed of generating images.
This may slow down some pipelines if the original images are very small. Set multi_threaded to False if slowdown is experienced:
python
p.sample(100, multi_threaded=False)
However, by default the sample() function uses multi-threading. This is currently only implemented when saving to disk. Generators will use multi-threading in the next version update.
Ground Truth Data
Images can be passed through the pipeline in groups of two or more so that ground truth data can be identically augmented.
| Original image and mask[3] | Augmented original and mask images |
|---------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------|
|
|
|
To augment ground truth data in parallel to any original data, add a ground truth directory to a pipeline using the ground_truth() function:
```python p = Augmentor.Pipeline("/path/to/images")
Point to a directory containing ground truth data.
Images with the same file names will be added as ground truth data
and augmented in parallel to the original data.
p.groundtruth("/path/to/groundtruth_images")
Add operations to the pipeline as normal:
p.rotate(probability=1, maxleftrotation=5, maxrightrotation=5) p.flipleftright(probability=0.5) p.zoomrandom(probability=0.5, percentagearea=0.8) p.fliptopbottom(probability=0.5) p.sample(50) ```
Multiple Mask/Image Augmentation
Using the DataPipeline class (Augmentor version >= 0.2.3), images that have multiple associated masks can be augmented:
| Multiple Mask Augmentation |
|----------------------------------------------------------------------------------------------------------|
|
|
Arbitrarily long lists of images can be passed through the pipeline in groups and augmented identically using the DataPipeline class. This is useful for ground truth images that have several masks, for example.
In the example below, the images and their masks are contained in the images data structure (as lists of lists), while their labels are contained in y:
```python p = Augmentor.DataPipeline(images, y) p.rotate(1, maxleftrotation=5, maxrightrotation=5) p.fliptopbottom(0.5) p.zoomrandom(1, percentagearea=0.5)
augmented_images, labels = p.sample(100) ```
The DataPipeline returns images directly (augmented_images above), and does not save them to disk, nor does it read data from the disk. Images are passed directly to DataPipeline during initialisation.
For details of the images data structure and how to create it, see the Multiple-Mask-Augmentation.ipynb Jupyter notebook.
Generators for Keras and PyTorch
If you do not wish to save to disk, you can use a generator (in this case with Keras):
python
g = p.keras_generator(batch_size=128)
images, labels = next(g)
which returns a batch of images of size 128 and their corresponding labels. Generators return data indefinitely, and can be used to train neural networks with augmented data on the fly.
Alternatively, you can integrate it with PyTorch:
python
import torchvision
transforms = torchvision.transforms.Compose([
p.torch_transform(),
torchvision.transforms.ToTensor(),
])
Main Features
Elastic Distortions
Using elastic distortions, one image can be used to generate many images that are real-world feasible and label preserving:
| Input Image | | Augmented Images |
|-----------------------------------------------------------------------------------------------------------------------------------|---|-------------------------------------------------------------------------------------------------------------------------|
|
| → |
|
The input image has a 1 pixel black border to emphasise that you are getting distortions without changing the size or aspect ratio of the original image, and without any black/transparent padding around the newly generated images.
The functionality can be more clearly seen here:
| Original Image[1] | Random distortions applied |
|---------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------|
|
|
|
Perspective Transforms
There are a total of 12 different types of perspective transform available. Four of the most common are shown below.
| Tilt Left | Tilt Right | Tilt Forward | Tilt Backward |
|---------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------|
|
|
|
|
|
The remaining eight types of transform are as follows:
| Skew Type 0 | Skew Type 1 | Skew Type 2 | Skew Type 3 |
|-----------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------|
|
|
|
|
|
| Skew Type 4 | Skew Type 5 | Skew Type 6 | Skew Type 7 |
|-----------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------|
|
|
|
|
|
Size Preserving Rotations
Rotations by default preserve the file size of the original images:
| Original Image | Rotated 10 degrees, automatically cropped |
|---------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------|
|
|
|
Compared to rotations by other software:
| Original Image | Rotated 10 degrees |
|---------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------|
|
|
|
Size Preserving Shearing
Shearing will also automatically crop the correct area from the sheared image, so that you have an image with no black space or padding.
| Original image | Shear (x-axis) 20 degrees | Shear (y-axis) 20 degrees |
|---------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------|
|
|
|
|
Compare this to how this is normally done:
| Original image | Shear (x-axis) 20 degrees | Shear (y-axis) 20 degrees |
|---------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------|
|
|
|
|
Cropping
Cropping can also be handled in a manner more suitable for machine learning image augmentation:
| Original image | Random crops + resize operation |
|---------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------|
|
|
|
Random Erasing
Random Erasing is a technique used to make models robust to occlusion. This may be useful for training neural networks used in object detection in navigation scenarios, for example.
| Original image[2] | Random Erasing |
|----------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
|
See the Pipeline.random_erasing() documentation for usage.
Chaining Operations in a Pipeline
With only a few operations, a single image can be augmented to produce large numbers of new, label-preserving samples:
| Original image | Distortions + mirroring |
|----------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------|
|
|
|
In the example above, we have applied three operations: first we randomly distort the image, then we flip it horizontally with a probability of 0.5 and then vertically with a probability of 0.5. We then sample from this pipeline 100 times to create 100 new data.
python
p.random_distortion(probability=1, grid_width=4, grid_height=4, magnitude=8)
p.flip_left_right(probability=0.5)
p.flip_top_bottom(probability=0.5)
p.sample(100)
Tutorial Notebooks
Integration with Keras using Generators
Augmentor can be used as a replacement for Keras' augmentation functionality. Augmentor can create a generator which produces augmented data indefinitely, according to the pipeline you have defined. See the following notebooks for details:
- Reading images from a local directory, augmenting them at run-time, and using a generator to pass the augmented stream of images to a Keras convolutional neural network, see
Augmentor_Keras.ipynb - Augmenting data in-memory (in array format) and using a generator to pass these new images to the Keras neural network, see
Augmentor_Keras_Array_Data.ipynb
Per-Class Augmentation Strategies
Augmentor allows for pipelines to be defined per class. That is, you can define different augmentation strategies on a class-by-class basis for a given classification problem.
See an example of this in the following Jupyter notebook: Per_Class_Augmentation_Strategy.ipynb
Complete Example
Let's perform an augmentation task on a single image, demonstrating the pipeline and several features of Augmentor.
First import the package and initialise a Pipeline object by pointing it to a directory containing your images:
```python import Augmentor
p = Augmentor.Pipeline("/home/user/augmentordatatests") ```
Now you can begin adding operations to the pipeline object:
python
p.rotate90(probability=0.5)
p.rotate270(probability=0.5)
p.flip_left_right(probability=0.8)
p.flip_top_bottom(probability=0.3)
p.crop_random(probability=1, percentage_area=0.5)
p.resize(probability=1.0, width=120, height=120)
Once you have added the operations you require, you can sample images from this pipeline:
python
p.sample(100)
Some sample output:
| Input Image[3] | | Augmented Images |
|--------------------------------------------------------------------------------------------------------------------|---|---------------------------------------------------------------------------------------------------------------------|
|
| → |
|
The augmented images may be useful for a boundary detection task, for example.
Licence and Acknowledgements
Augmentor is made available under the terms of the MIT Licence. See Licence.md.
[1] Checkerboard image obtained from Wikimedia Commons and is in the public domain: https://commons.wikimedia.org/wiki/File:Checkerboard_pattern.svg
[2] Street view image is in the public domain: http://stokpic.com/project/italian-city-street-with-shoppers/
[3] Skin lesion image obtained from the ISIC Archive:
- Image id = 5436e3abbae478396759f0cf
- Download: https://isic-archive.com:443/api/v1/image/5436e3abbae478396759f0cf/download
You can use urllib to obtain the skin lesion image in order to reproduce the augmented images above:
```python
from urllib import urlretrieve imurl = "https://isic-archive.com:443/api/v1/image/5436e3abbae478396759f0cf/download" urlretrieve(imurl, "ISIC0000000.jpg") ('ISIC0000000.jpg',
) ```
Note: For Python 3, use from urllib.request import urlretrieve.
Logo created at LogoMakr.com
Tests
To run the automated tests, clone the repository and run:
bash
$ py.test -v
from the command line. To view the CI tests that are run after each commit, see https://travis-ci.org/mdbloice/Augmentor.
Asciicast
Click the preview below to view a video demonstration of Augmentor in use:
Owner
- Name: Marcus D. Bloice
- Login: mdbloice
- Kind: user
- Location: Graz, Austria
- Company: Medical University Graz
- Website: https://imi.medunigraz.at
- Repositories: 3
- Profile: https://github.com/mdbloice
Medical Imaging, Machine Learning
JOSS Publication
Augmentor: An Image Augmentation Library for Machine Learning
Authors
Tags
image augmentation machine learning neural networksGitHub Events
Total
- Issues event: 3
- Watch event: 74
- Pull request event: 1
- Fork event: 8
Last Year
- Issues event: 3
- Watch event: 74
- Pull request event: 1
- Fork event: 8
Committers
Last synced: 5 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| Marcus Bloice | m****e@m****t | 464 |
| Lukas Radacher | l****r@g****m | 6 |
| Johannes Lüftenegger | j****r@s****t | 5 |
| Kevin Mader | k****r@4****m | 5 |
| June Oh | me@j****m | 4 |
| YananJian | j****n@g****m | 3 |
| DeanZhang | d****l@g****m | 2 |
| Eddie S | e****e@v****m | 2 |
| Jacob Silterra | g****b@j****m | 1 |
| Ruslan Israfilov | r****v@i****m | 1 |
| Tobias Ollmann | t****s@h****t | 1 |
| Amartya R. Saikia | a****a@g****m | 1 |
| Christof Stocker | c****r@h****g | 1 |
| Dmitrii Pukhov | p****n@y****u | 1 |
| Jurriaan Barkey Wolf | j****f@g****m | 1 |
| Lewis | l****s@d****o | 1 |
| Martin Drawitsch | m****h@g****m | 1 |
| Martin Gauthier | g****6@g****m | 1 |
| Paul Angerer | p****r@g****t | 1 |
| Simona Jokubauskaite | s****e@g****m | 1 |
| Vendula Svendova | s****a@g****m | 1 |
| aniket sharma | a****s@g****m | 1 |
| daisukelab | n****e@g****m | 1 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 4 months ago
All Time
- Total issues: 91
- Total pull requests: 16
- Average time to close issues: about 1 month
- Average time to close pull requests: 5 months
- Total issue authors: 84
- Total pull request authors: 15
- Average comments per issue: 2.1
- Average comments per pull request: 1.19
- Merged pull requests: 3
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 3
- Pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 3
- Pull request authors: 0
- Average comments per issue: 0.0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- ccl-private (4)
- Mahi-Mai (2)
- MasIgor (2)
- eemberda (2)
- rstml (2)
- cemtorun (1)
- puhoshville (1)
- gmonkman (1)
- NithyaMogane-TomTom (1)
- ajaykmr2292 (1)
- Salehoof (1)
- weiminson (1)
- monkeycc (1)
- Abhishaike (1)
- zhaoxin111 (1)
Pull Request Authors
- romain-xu-darme (2)
- puhoshville (2)
- Ares-Liang (1)
- gachiemchiep (1)
- Smellly (1)
- sizhky (1)
- claydugo (1)
- rstml (1)
- boykovdn (1)
- trianxy (1)
- PyDeps (1)
- itstechaj (1)
- jjhbw (1)
- LeninGF (1)
- JasonnnW3000 (1)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 13
-
Total downloads:
- pypi 7,999 last-month
- Total docker downloads: 10
-
Total dependent packages: 0
(may contain duplicates) -
Total dependent repositories: 16
(may contain duplicates) - Total versions: 39
- Total maintainers: 2
alpine-v3.18: py3-augmentor-pyc
Precompiled Python bytecode for py3-augmentor
- Homepage: https://github.com/mdbloice/Augmentor
- License: MIT
-
Latest release: 0.2.12-r1
published over 2 years ago
Rankings
Maintainers (1)
alpine-v3.18: py3-augmentor
Image augmentation library in Python for machine learning
- Homepage: https://github.com/mdbloice/Augmentor
- License: MIT
-
Latest release: 0.2.12-r1
published over 2 years ago
Rankings
Maintainers (1)
pypi.org: augmentor
Image augmentation library for Machine Learning
- Homepage: https://github.com/mdbloice/Augmentor
- Documentation: https://augmentor.readthedocs.io/
- License: MIT
-
Latest release: 0.2.12
published almost 3 years ago
Rankings
Maintainers (1)
alpine-edge: py3-augmentor-pyc
Precompiled Python bytecode for py3-augmentor
- Homepage: https://github.com/mdbloice/Augmentor
- License: MIT
-
Latest release: 0.2.12-r2
published over 1 year ago
Rankings
Maintainers (1)
alpine-edge: py3-augmentor
Image augmentation library in Python for machine learning
- Homepage: https://github.com/mdbloice/Augmentor
- License: MIT
-
Latest release: 0.2.12-r2
published over 1 year ago
Rankings
Maintainers (1)
alpine-v3.20: py3-augmentor
Image augmentation library in Python for machine learning
- Homepage: https://github.com/mdbloice/Augmentor
- License: MIT
-
Latest release: 0.2.12-r2
published over 1 year ago
Rankings
Maintainers (1)
alpine-v3.19: py3-augmentor
Image augmentation library in Python for machine learning
- Homepage: https://github.com/mdbloice/Augmentor
- License: MIT
-
Latest release: 0.2.12-r1
published over 2 years ago
Rankings
Maintainers (1)
alpine-v3.19: py3-augmentor-pyc
Precompiled Python bytecode for py3-augmentor
- Homepage: https://github.com/mdbloice/Augmentor
- License: MIT
-
Latest release: 0.2.12-r1
published over 2 years ago
Rankings
Maintainers (1)
alpine-v3.22: py3-augmentor-pyc
Precompiled Python bytecode for py3-augmentor
- Homepage: https://github.com/mdbloice/Augmentor
- License: MIT
-
Latest release: 0.2.12-r2
published over 1 year ago
Rankings
Maintainers (1)
alpine-v3.21: py3-augmentor-pyc
Precompiled Python bytecode for py3-augmentor
- Homepage: https://github.com/mdbloice/Augmentor
- License: MIT
-
Latest release: 0.2.12-r2
published over 1 year ago
Rankings
Maintainers (1)
alpine-v3.21: py3-augmentor
Image augmentation library in Python for machine learning
- Homepage: https://github.com/mdbloice/Augmentor
- License: MIT
-
Latest release: 0.2.12-r2
published over 1 year ago
Rankings
Maintainers (1)
alpine-v3.22: py3-augmentor
Image augmentation library in Python for machine learning
- Homepage: https://github.com/mdbloice/Augmentor
- License: MIT
-
Latest release: 0.2.12-r2
published over 1 year ago
Rankings
Maintainers (1)
alpine-v3.20: py3-augmentor-pyc
Precompiled Python bytecode for py3-augmentor
- Homepage: https://github.com/mdbloice/Augmentor
- License: MIT
-
Latest release: 0.2.12-r2
published over 1 year ago
Rankings
Maintainers (1)
Dependencies
- actions/setup-python v2 composite
- actions/checkout v2 composite
- actions/setup-python v2 composite
- keras ==2.1.3
- Pillow * development
- numpy * development
- pytest * development
- tqdm * development
- Pillow *
- numpy *
- tqdm *
- Pillow >=5.2.0
- future >=0.16.0
- futures >=3.2.0
- numpy >=1.11.0
- tqdm >=4.9.0

