Discover augmentation strategies tailored for your data
Project description
DeepAugment
DeepAugment discovers optimized augmentation strategies tailored for your images. It uses Bayesian Optimization for optimizing hyperparameters for augmentation. The tool:
- reduces error rate of CNN models (shown 37% decrease in error for CIFAR-10 on WRN-28-10 compared to no augmentation)
- saves times by automating the process
Resources: slides
Installation/Usage
Example: google-colab
$ pip install deepaugment
Simple usage (with any dataset)
from deepaugment.deepaugment import DeepAugment
deepaug = DeepAugment(my_images, my_labels)
best_policies = deepaug.optimize(300)
Simple usage (with a dataset on keras)
deepaug = DeepAugment("cifar10")
best_policies = deepaug.optimize(300)
Advanced usage
from keras.datasets import fashion_mnist
# my configuration
my_config = {
"model": "basiccnn",
"method": "bayesian_optimization",
"train_set_size": 2000,
"opt_samples": 3,
"opt_last_n_epochs": 3,
"opt_initial_points": 10,
"child_epochs": 50,
"child_first_train_epochs": 0,
"child_batch_size": 64
}
(x_train, y_train), (x_test, y_test) = fashion_mnist.load_data()
# X_train.shape -> (N, M, M, 3)
# y_train.shape -> (N)
deepaug = DeepAugment(iamges=x_train, labels=y_train, config=my_config)
best_policies = deepaug.optimize(300)
Results
CIFAR-10 best policies tested on WRN-28-10
- Method: Wide-ResNet-28-10 trained with CIFAR-10 augmented images by best found policies, and with unaugmented images (everything else same).
- Result: 5.2% accuracy increase by DeepAugment
How it works
Package consists three main components: controller, augmenter, and child model. Overal workflow is that controller samples new augmentation policies, augmenter transforms images by the new policy, and child model is trained from scratch by augmented images. Then, a reward is calculated from child model's validation accuracy curve by the formula as explained at (reward function section). This reward is returned back to controller, and it updates its internal and samples a new augmentation policy, returning to the beginning of the cycle.
Controller might be set to use Bayesian Optimization (defaul), or Random Search. If Bayesian Optimization set, it samples new policies by a Random Forest Estimator.
Why Bayesian Optimization?
In hyperparameter optimization, main choices are random search, grid search, bayesian optimization, and reinforcement learning (in the order of method complexity). Google's AutoAugment uses Reinforcement Learning for the data augmentation hyperparameter tuning, but it takes 15,000 iterations to learn policies (which means training the child CNN model 15,000 times). Thus, it requires huge computational resources. Bayesian Optimization on the other hand learns good polices in 100-300 iterations, making it +40X faster. Additionally, Bayesian Optimization beats grid search and random search in terms of accuracy, cost, and computation time (ref) in hyperparameter tuning.
How does Bayesian Optimization work?
- Build a surrogate probability model of the objective function
- Find the hyperparameters that perform best on the surrogate
- Apply these hyperparameters to the true objective function
- Update the surrogate model incorporating the new results
- Repeat steps 2–4 until max iterations or time is reached
Augmentation policy
A policy describes the augmentation will be applied on a dataset. Each policy consists variables for two augmentation types, their magnitude and the portion of the data to be augmented. An example policy is as following:
There are currently 20 types of augmentation techniques (above, right) that each aug. type variable can take. All techniques are (this list might grow in later versions):
AUG_TYPES = [ "crop", "gaussian-blur", "rotate", "shear", "translate-x", "translate-y", "sharpen", "emboss", "additive-gaussian-noise", "dropout", "coarse-dropout", "gamma-contrast", "brighten", "invert", "fog", "clouds", "add-to-hue-and-saturation", "coarse-salt-pepper", "horizontal-flip", "vertical-flip"]
Child model
Reward function
Reward function is calculated as mean of K highest validation accuracies of the child model which is not smaller than corresponding training accuracy by 0.05. K can be determined by the user by updating opt_last_n_epochs
key in config dictionary as argument to DeepAugment()
class (K is 3 by default).
Data pipeline
Class diagram
Package diagram
--------Contact
Baris Ozmen, hbaristr@gmail.com
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file deepaugment-0.12.4.tar.gz
.
File metadata
- Download URL: deepaugment-0.12.4.tar.gz
- Upload date:
- Size: 26.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8dc2287461c753d86a79acb14de7cbe467b3a8567346e53e1d99344dd8748db2 |
|
MD5 | 70d30cb0a6527c74da018de05789b983 |
|
BLAKE2b-256 | 326c229513b5335bf398f5f0fde075631a1dddf961216d21c8ae7ae0124d57fc |
File details
Details for the file deepaugment-0.12.4-py2.py3-none-any.whl
.
File metadata
- Download URL: deepaugment-0.12.4-py2.py3-none-any.whl
- Upload date:
- Size: 29.7 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01b92425ef2aa73d0de236f8bd8e1df71f11e490d7e9b4a5ffdf7f4ea65c8337 |
|
MD5 | ba666e8f1ce8ec1d267afaafd13333c4 |
|
BLAKE2b-256 | 1e58144a4467a56e71f2edacc8491ef044c7b31ed40de79e4b5b4544228acf4c |