This is the official implementation of TrivialAugment and a mini-library for the application of multiple image augmentation strategies including RandAugment and TrivialAugment.

Overview

Trivial Augment

This is the official implementation of TrivialAugment (https://arxiv.org/abs/2103.10158), as was used for the paper. TrivialAugment is a super simple, but state-of-the-art performing, augmentation algorithm.

We distribute this implementation with two main use cases in mind. Either you only use our (re-)implementetations of practical augmentation methods or you start off with our full codebase.

Use TrivialAugment and Other Methods in Your Own Codebase

In this case we recommend to simply copy over the file aug_lib.py to your codebase. You can now instantiate the augmenters TrivialAugment, RandAugment and UniAugment like this:

augmenter = aug_lib.TrivialAugment()

And simply use them on a PIL images img:

aug_img = augmenter(img)

This format also happens to be compatible with torchvision.transforms. If you do not have Pillow or numpy installed, do so by calling pip install Pillow numpy. Generally, a good position to augment an image with the augmenter is right as you get it out of the dataset, before you apply any custom augmentations.

The default augmentation space is fixed_standard, that is without AutoAugments posterization bug and using the set of augmentations used in Randaugment. This is the search space we used for all our experiments, that do not mention another augmentation space. You can change the augmentation space, though, with aug_lib.set_augmentation_space. This call for example

aug_lib.set_augmentation_space('fixed_custom',2,['cutout'])

will change the augmentation space to only ever apply cutout with a large width or nothing. The 2 here gives indications in how many strength levels the strength ranges of the augmentation space should be divided. If an augmentation space includes sample_pairing, you need to specify a set of images with which to pair before each step: aug_lib.blend_images = [LIST OF PIL IMAGES].

Our recommendation is to use the default fixed_standard search space for very cheap setups, like Wide-Resnet-40-2, and to use wide_standard for all other setups by calling aug_lib.set_augmentation_space('wide_standard',31) before the start of training.

Use Our Full Codebase

Clone this directory and cd into it.

git clone automl/trivialaugment
cd trivialaugment

Install a fitting PyTorch version for your setup with GPU support, as our implementation only support setups with at least one CUDA device and install our requirements:

pip install -r requirements.txt
# Install a pytorch version, in many setups this has to be done manually, see pytorch.org

Now you should be ready to go. Start a training like so:

python -m TrivialAugment.train -c confs/wresnet40x2_cifar100_b128_maxlr.1_ta_fixedsesp_nowarmup_200epochs.yaml --dataroot data --tag EXPERIMENT_NAME

For concrete configs of experiments from the paper see the comments in the papers LaTeX code around the number you want to reproduce. For logs and metrics use a tensorboard with the logs directory or use our aggregate_results.py script to view data from the tensorboard logs in the command line.

Confidence Intervals

Since in the current literature we rarely found confidence intervals, we share our implementation in evaluation_tools.py.

This repository uses code from https://github.com/ildoonet/pytorch-randaugment and from https://github.com/tensorflow/models/tree/master/research/autoaugment.

Comments
  • Probability of applying a transform

    Probability of applying a transform

    Hi Samuel,

    Thanks for your fantastic work, even if TrivialAugment was a bit worse than all the other RL-based approaches, it should still be preferrable, given its very low cost and straightforward implementation, I think.

    I am trying to understand your implementation in auglib.py in order to modify it to suit my purposes, and I am seeing that, in the standard search spaces, both fixed and wide, the geometric transforms inside ALL_TRANSFORMS (this is, rotate, translates, shears) all have a 50% chance of being applied. This is not true for the intensity-based transforms, though. I think (might be wrong) that this is not mentioned in the paper, e.g. in fig. 1 or the algorithm listing in page 4. So, may I ask if you used the 50% chance of switching off geometric transforms in your experiments?

    Thanks!

    Adrian

    opened by agaldran 10
  • Declining test results

    Declining test results

    Hello!Hi, the following code was used directly in my model: transforms.Compose([transforms.TrivialAugmentWide(),transforms.RandomResizedCrop(224),transforms.RandomHorizontalFlip(), transforms. ToTensor(), transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])]) after I found that both validation loss and training loss increased on mobilev2 and resnet50 , am I using the wrong method?The training set is the flower dataset

    opened by xiaobai-marker 9
  • Loader or Transform()

    Loader or Transform()

    Is there an easy way to make a DataLoader, or for example ImageFolder, or to use something like transforms = [ToTensor(), TrivialAugment()] ? Because, a quick look let me to believe that TrivialAugment(img) is needed for the latter and this is not accepted as a standard torch Transform.

    opened by mens-artis 6
  • Can not start without fix train.py

    Can not start without fix train.py

    Have bug, described bellow:
    File "../trivialaugment/TrivialAugment/train.py", line 353, in spawn_process assert worldsize == C.get()['gpus'], f"Did not specify the number of GPUs in Config with which it was started: {worldsize} vs {C.get()['gpus']}"

    It happens due to incorrect unpacking "args.config". need to use "args.config[0]" instead "args.config" (line: 343-344). After this it work right :)

    opened by gertelrina 4
  • question about

    question about "aug_lib.blend_images" in train.py?

    Hi, could you please tell me how did you train your model? Because I found in train.py that "aug_lib.blend_images" does not calculate loss during the training process, I don't know how the enhanced data adjusts the model. I would be very grateful if you could reply me.

    opened by Tomlk 2
  • TA for Object Detection

    TA for Object Detection

    Hi, firstly thank you for sharing this finding, it is really interesting to find that after going one big round, the simple solutions might work the best after all.

    Saw that you all did point out at the end of the paper that TA does not extend well for Object Detection task. Is it possible to share more details regarding this, and what sort of tuning you all did?

    opened by levan92 2
  • What is the reason for having 30 bins of possible strengths?

    What is the reason for having 30 bins of possible strengths?

    Hello. Thanks for the work and code. Do not understand why do we need to have 30 bins in the end, why not just to sample augmentation strength uniformly in the specific intervals? Do we need a granularity? What is the intuinition behind this?

    opened by snarb 1
  • Do sharpness and auto_contrast do much?

    Do sharpness and auto_contrast do much?

    Hi, I'm currently trying to find the perfect trivial augmentation policy for my problem. When I apply the auto_contrast or sharpness at 2 strength levels and i display a few augmentations, i can't tell if there happens anything compared to the original image. I've already tried to rise the minVal but nothing changed. Here's a minimal working example

    from PIL import Image
    import aug_lib
    
    orig_img = Image.open('pizza.jpeg')
    aug_lib.set_augmentation_space(augmentation_space='wide_standard_custom', 
                                               num_strengths=2, 
                                               custom_augmentation_space_augs=["auto_contrast" ]) # or sharpness                                                                   
    augmenter = aug_lib.TrivialAugment()
    for _ in range(4):
        display(augmenter(orig_img))
    

    Thanks in advance for your commitment!

    Kind regards, Johannes

    opened by jfltzngr 0
Owner
AutoML-Freiburg-Hannover
AutoML-Freiburg-Hannover
Code of U2Fusion: a unified unsupervised image fusion network for multiple image fusion tasks, including multi-modal, multi-exposure and multi-focus image fusion.

U2Fusion Code of U2Fusion: a unified unsupervised image fusion network for multiple image fusion tasks, including multi-modal (VIS-IR, medical), multi

Han Xu 129 Dec 11, 2022
Image transformations designed for Scene Text Recognition (STR) data augmentation. Published at ICCV 2021 Workshop on Interactive Labeling and Data Augmentation for Vision.

Data Augmentation for Scene Text Recognition (ICCV 2021 Workshop) (Pronounced as "strog") Paper Arxiv Why it matters? Scene Text Recognition (STR) req

Rowel Atienza 152 Dec 28, 2022
Official PyTorch implementation of MX-Font (Multiple Heads are Better than One: Few-shot Font Generation with Multiple Localized Experts)

Introduction Pytorch implementation of Multiple Heads are Better than One: Few-shot Font Generation with Multiple Localized Expert. | paper Song Park1

Clova AI Research 97 Dec 23, 2022
The source code for the Cutoff data augmentation approach proposed in this paper: "A Simple but Tough-to-Beat Data Augmentation Approach for Natural Language Understanding and Generation".

Cutoff: A Simple Data Augmentation Approach for Natural Language This repository contains source code necessary to reproduce the results presented in

Dinghan Shen 49 Dec 22, 2022
Fast image augmentation library and easy to use wrapper around other libraries. Documentation: https://albumentations.ai/docs/ Paper about library: https://www.mdpi.com/2078-2489/11/2/125

Albumentations Albumentations is a Python library for image augmentation. Image augmentation is used in deep learning and computer vision tasks to inc

null 11.4k Jan 9, 2023
A mini library for Policy Gradients with Parameter-based Exploration, with reference implementation of the ClipUp optimizer from NNAISENSE.

PGPElib A mini library for Policy Gradients with Parameter-based Exploration [1] and friends. This library serves as a clean re-implementation of the

NNAISENSE 56 Jan 1, 2023
Vanilla and Prototypical Networks with Random Weights for image classification on Omniglot and mini-ImageNet. Made with Python3.

vanilla-rw-protonets-project Vanilla Prototypical Networks and PNs with Random Weights for image classification on Omniglot and mini-ImageNet. Made wi

Giovani Candido 8 Aug 31, 2022
Image augmentation library in Python for machine learning.

Augmentor is an image augmentation library in Python for machine learning. It aims to be a standalone library that is platform and framework independe

Marcus D. Bloice 4.8k Jan 7, 2023
Mini-hmc-jax - A simple implementation of Hamiltonian Monte Carlo in JAX

mini-hmc-jax This is a simple implementation of Hamiltonian Monte Carlo in JAX t

Martin Marek 6 Mar 3, 2022
Official PyTorch implementation for Generic Attention-model Explainability for Interpreting Bi-Modal and Encoder-Decoder Transformers, a novel method to visualize any Transformer-based network. Including examples for DETR, VQA.

PyTorch Implementation of Generic Attention-model Explainability for Interpreting Bi-Modal and Encoder-Decoder Transformers 1 Using Colab Please notic

Hila Chefer 489 Jan 7, 2023
Official Pytorch Implementation of Adversarial Instance Augmentation for Building Change Detection in Remote Sensing Images.

IAug_CDNet Official Implementation of Adversarial Instance Augmentation for Building Change Detection in Remote Sensing Images. Overview We propose a

null 53 Dec 2, 2022
Official implementation of the paper "AAVAE: Augmentation-AugmentedVariational Autoencoders"

AAVAE Official implementation of the paper "AAVAE: Augmentation-AugmentedVariational Autoencoders" Abstract Recent methods for self-supervised learnin

Grid AI Labs 48 Dec 12, 2022
StyleGAN2 with adaptive discriminator augmentation (ADA) - Official TensorFlow implementation

StyleGAN2 with adaptive discriminator augmentation (ADA) — Official TensorFlow implementation Training Generative Adversarial Networks with Limited Da

NVIDIA Research Projects 1.7k Dec 29, 2022
Official PyTorch implementation of the ICRA 2021 paper: Adversarial Differentiable Data Augmentation for Autonomous Systems.

Adversarial Differentiable Data Augmentation This repository provides the official PyTorch implementation of the ICRA 2021 paper: Adversarial Differen

Manli 3 Oct 15, 2022
Team nan solution repository for FPT data-centric competition. Data augmentation, Albumentation, Mosaic, Visualization, KNN application

FPT_data_centric_competition - Team nan solution repository for FPT data-centric competition. Data augmentation, Albumentation, Mosaic, Visualization, KNN application

Pham Viet Hoang (Harry) 2 Oct 30, 2022
PyTorch Implementation for AAAI'21 "Do Response Selection Models Really Know What's Next? Utterance Manipulation Strategies for Multi-turn Response Selection"

UMS for Multi-turn Response Selection Implements the model described in the following paper Do Response Selection Models Really Know What's Next? Utte

Taesun Whang 47 Nov 22, 2022
Code of 3D Shape Variational Autoencoder Latent Disentanglement via Mini-Batch Feature Swapping for Bodies and Faces

3D Shape Variational Autoencoder Latent Disentanglement via Mini-Batch Feature Swapping for Bodies and Faces Installation After cloning the repo open

null 37 Dec 3, 2022
A mini lib that implements several useful functions binding to PyTorch in C++.

Torch-gather A mini library that implements several useful functions binding to PyTorch in C++. What does gather do? Why do we need it? When dealing w

maxwellzh 8 Sep 7, 2022