在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):mdbloice/Augmentor开源软件地址(OpenSource Url):https://github.com/mdbloice/Augmentor开源编程语言(OpenSource Language):Python 100.0%开源软件介绍(OpenSource Introduction):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. InstallationAugmentor 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 install Augmentor See the documentation for building from source. To upgrade from a previous version, use DocumentationComplete documentation can be found on Read the Docs: http://augmentor.readthedocs.io/ Quick Start Guide and UsageThe 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 import Augmentor
p = Augmentor.Pipeline("/path/to/images") You can then add operations to the Pipeline object 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: 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 If you wish to process each image in the pipeline exactly once, use 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 Multi-threadingAugmentor (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 p.sample(100, multi_threaded=False) However, by default the Ground Truth DataImages can be passed through the pipeline in groups of two or more so that ground truth data can be identically augmented.
To augment ground truth data in parallel to any original data, add a ground truth directory to a pipeline using the ground_truth() function: 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.ground_truth("/path/to/ground_truth_images")
# Add operations to the pipeline as normal:
p.rotate(probability=1, max_left_rotation=5, max_right_rotation=5)
p.flip_left_right(probability=0.5)
p.zoom_random(probability=0.5, percentage_area=0.8)
p.flip_top_bottom(probability=0.5)
p.sample(50) Multiple Mask/Image AugmentationUsing the
Arbitrarily long lists of images can be passed through the pipeline in groups and augmented identically using the In the example below, the images and their masks are contained in the p = Augmentor.DataPipeline(images, y)
p.rotate(1, max_left_rotation=5, max_right_rotation=5)
p.flip_top_bottom(0.5)
p.zoom_random(1, percentage_area=0.5)
augmented_images, labels = p.sample(100) The For details of the Generators for Keras and PyTorchIf you do not wish to save to disk, you can use a generator (in this case with Keras): 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: import torchvision
transforms = torchvision.transforms.Compose([
p.torch_transform(),
torchvision.transforms.ToTensor(),
]) Main FeaturesElastic DistortionsUsing elastic distortions, one image can be used to generate many images that are real-world feasible and label preserving:
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:
Perspective TransformsThere are a total of 12 different types of perspective transform available. Four of the most common are shown below.
The remaining eight types of transform are as follows:
Size Preserving RotationsRotations by default preserve the file size of the original images:
Compared to rotations by other software:
Size Preserving ShearingShearing will also automatically crop the correct area from the sheared image, so that you have an image with no black space or padding.
Compare this to how this is normally done:
CroppingCropping can also be handled in a manner more suitable for machine learning image augmentation:
Random ErasingRandom 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.
See the Pipeline.random_erasing() documentation for usage. Chaining Operations in a PipelineWith only a few operations, a single image can be augmented to produce large numbers of new, label-preserving samples:
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. 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 NotebooksIntegration with Keras using GeneratorsAugmentor 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:
Per-Class Augmentation StrategiesAugmentor 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: Complete ExampleLet'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: import Augmentor
p = Augmentor.Pipeline("/home/user/augmentor_data_tests") Now you can begin adding operations to the pipeline object: 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: p.sample(100) Some sample output:
The augmented images may be useful for a boundary detection task, for example. Licence and AcknowledgementsAugmentor is made available under the terms of the MIT Licence. See [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:
You can use >>> from urllib import urlretrieve
>>> im_url = "https://isic-archive.com:443/api/v1/image/5436e3abbae478396759f0cf/download"
>>> urlretrieve(im_url, "ISIC_0000000.jpg")
('ISIC_0000000.jpg', <httplib.HTTPMessage instance at 0x7f7bd949a950>) Note: For Python 3, use Logo created at LogoMakr.com TestsTo run the automated tests, clone the repository and run: $ 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. AsciicastClick the preview below to view a video demonstration of Augmentor in use: |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论