AI Logic

Data Augmentation

Population Based Augmentation (PBA)

Updated:

PBA diagram. The left shows the flow for searching for a policy schedule (train 16 child models in parallel; every 3 epochs, the bottom 25% by validation accuracy copy the weights and policy of the top 25% and slightly change the values; the sequence of policies of the best child model is used for the final training). The right shows how the policy for one epoch is applied (shuffle the 30 operations, draw an upper limit of 0 to 2 with probabilities 0.2, 0.3, and 0.5, and apply operations selected by probability up to the limit) and how the values are changed

What is PBA

Population Based Augmentation (PBA) is a method that automatically searches for a data augmentation policy (which operations to apply, with what probability and magnitude). It was proposed by Ho et al. in 2019 and presented at ICML 2019.

Its predecessor, AutoAugment, searches for a "fixed policy" used unchanged from the start to the end of training, and its search on CIFAR-10 alone took 5,000 GPU hours. PBA changes two things and finds policies of nearly the same accuracy in 5 GPU hours.

  • It searches for a "policy schedule" instead of a fixed policy: It learns a function f(x,t)f(x, t) whose policy changes from epoch to epoch (xx is the image and tt is the current epoch).
  • It uses Population Based Training for the search: With Population Based Training (PBT), training the child models and tuning the policy proceed at the same time. There is no need to retrain a child model from scratch to the end for each policy.

As an analogy, instead of trying many workout plans that each "use the same weight from start to finish," several people train at the same time, copy the plan of whoever is improving, and gradually change the weights. What remains at the end is a record of "when, and how heavy the weights were" (the schedule).

What PBA ultimately uses is not the child models trained during the search but only the policy schedule. The schedule it finds is used for the actual training of a larger model.

Policy format (what is searched)

To make comparison with AutoAugment easy, PBA uses the same operations and magnitude levels (the 16 operations of AutoAugment minus Sample Pairing, i.e., 15 operations).

  • Policy: 30 tuples of "(operation, probability, magnitude)." Each of the 15 operations appears twice, and the operations are fixed. What is searched is the 60 values of probability and magnitude.
  • Probability: 0 to 100% in steps of 10% (11 levels)
  • Magnitude: 0 to 9 (10 levels). Some operations, such as AutoContrast, Equalize, and Invert, do not use magnitude.

A policy is applied to an image as follows (Algorithm 1 in the paper; right side of the figure at the top).

  1. Shuffle the order of the 30 tuples at random.
  2. Choose the upper limit count of operations to apply from 0, 1, and 2 with probabilities 0.2, 0.3, and 0.5.
  3. In the shuffled order, apply each operation that is selected by its tuple's probability at that tuple's magnitude. Stop after count operations have been applied.

In a schedule, these 60 values change every epoch. A single policy can be chosen in (10×11)30≈1.75×1061(10 \times 11)^{30} \approx 1.75 \times 10^{61} ways, which the paper notes is a larger space than AutoAugment's 2.8×10322.8 \times 10^{32}.

Although the search space is much larger, the search is faster. The paper explains that good schedules often change smoothly over time, which makes them easy to find with an incremental search like PBT.

Search procedure

The search consists of a single PBT run (left side of the figure at the top). The steps below use the paper's CIFAR-10 settings.

  1. Prepare a small dataset and child models: Take 4,000 images from CIFAR-10 (1,000 for SVHN) and prepare 16 Wide-ResNet-40-2 child models.
  2. Start the policy at zero: Set every probability and magnitude to 0. The paper reasons that early in training, validation accuracy is close to training accuracy, so little data augmentation is needed.
  3. Train in parallel one epoch at a time: Train the 16 child models, each applying data augmentation with its current policy.
  4. Evaluate on validation data: Measure each child model's accuracy on validation data separate from the final test data.
  5. Exploit (copy): Among child models that have trained for 3 more epochs, those in the bottom 25% copy the weights and policy of a child model in the top 25% as is.
  6. Explore (perturb): For each value of the copied policy, resample it uniformly from its range with probability 0.2; otherwise, pick 0 to 3 steps uniformly and shift the value up or down by that amount (clamping it to the edge if it leaves the range).
  7. Repeat steps 3–6 until epoch 200.
  8. Extract the schedule: Take the sequence of policies followed by the best child model as the policy schedule.

When the final training is long (1,800 epochs for Shake-Shake and PyramidNet), the 200-epoch schedule is stretched proportionally.

Because child model weights are only copied and never retrained from scratch, the total computation is just "training one child model × 16."

AutoAugmentPBA
Policies triedAbout 15,000 (a child model trained for 120 epochs for each)16 child models trained once (200 epochs)
Total training epochsAbout 1.8 million3,200 (less than 1/500)
GPU hours for the CIFAR-10 search5,000 (converted to Tesla P100)5 (Titan XP)
GPU hours for the SVHN search1,0001

According to the paper, random search over policies needed to train more than 250 child models to approach the child model accuracy reached by a single PBA run (16 models).

Results reported in the paper

The test error rates (%, average of 5 runs) when final models are trained with the schedules found are as follows. "Standard" means cropping and horizontal flipping, Cutout adds 16 × 16 (20 × 20 for SVHN) Cutout on top of that, and AutoAugment and PBA apply their policies on top of that. For CIFAR-100, the schedule found on CIFAR-10 is used as is.

DatasetModelStandardCutoutAutoAugmentPBA
CIFAR-10Wide-ResNet-28-103.873.082.682.58
CIFAR-10Shake-Shake (26 2x96d)2.862.561.992.03
CIFAR-10Shake-Shake (26 2x112d)2.822.571.892.03
CIFAR-10PyramidNet + ShakeDrop2.672.311.481.46
CIFAR-100Wide-ResNet-28-1018.818.4117.0916.73
CIFAR-100PyramidNet + ShakeDrop13.9912.1910.6710.94
SVHN (including extra data)Wide-ResNet-28-101.501.401.131.18
  • CIFAR-10: The 1.46% with PyramidNet + ShakeDrop slightly beat the best error rate at the time of publication (AutoAugment's 1.48%). With Shake-Shake, PBA fell slightly short of AutoAugment.
  • SVHN: Because AutoAugment's SVHN evaluation code was not public, the paper compares against its own re-evaluation of AutoAugment (1.13%) (the value in the AutoAugment paper is 1.07%).

Effect of using a schedule (CIFAR-10, Wide-ResNet-28-10, Table 3)

Policy used for trainingError rate (%)
Cutout only3.08
Fix the last policy of the schedule2.76
Keep each policy's duration but shuffle their order2.66
Pick a policy per batch with probability proportional to its duration2.89
PBA schedule2.58

Fixing the last policy worsens the error rate, and the paper states that for this model about half of the improvement over Cutout is lost. Shuffling the order also makes it worse, so "which policy is used when" matters. The paper attributes the effect to being able to apply "easy" data augmentation early in training and "hard" data augmentation later. In the schedule found, magnitude rose sharply early in training and leveled off around epoch 130.

Caveats

A schedule found is tied to the number of epochs it was searched for: Because the schedule is a function of the epoch, it needs adjusting, such as stretching it proportionally, when the final training has a different length. The paper stretches a schedule searched over 200 epochs to 1,800 epochs but does not verify whether that stretching is optimal.

  • The search needs infrastructure for running PBT: The paper's implementation uses PBT in Ray (Tune). It trains several child models in parallel on a single GPU.
  • Results searched with a small dataset and small model are applied to larger models: As with AutoAugment, the search runs on a proxy task. In the paper, some models, such as Shake-Shake, fell slightly short of AutoAugment.
  • The policy format follows AutoAugment's: The paper barely tunes the distribution of the upper limit on the number of operations or the levels of magnitude and probability. It states that the format was chosen for comparison with AutoAugment, not as the result of searching for the best format.
  • Evaluated on CIFAR and SVHN: The paper's experiments are on CIFAR-10, CIFAR-100, and SVHN; there are no results on large datasets such as ImageNet.

Comparison with similar methods and how to choose

The table below lines up methods that automatically decide data augmentation policies from the same angles. Error rates (%) are for PyramidNet + ShakeDrop on CIFAR-10, taken from each paper.

MethodWhat is searchedHow it searchesSearch cost (CIFAR-10)Error rate
AutoAugmentFixed policyTrains a child model for each policy and searches with reinforcement learning5,000 GPU hours1.5
Fast AutoAugmentFixed policyMeasures loss with a trained model and searches with Bayesian optimization3.5 GPU hours1.7
PBAPolicy scheduleSearches with PBT while training child models5 GPU hours1.46
RandAugmentTwo values: number of operations and magnitudeGrid search on the target taskNo search stage1.5
TrivialAugmentNothingNo searchNo search stage1.4

Rough guidelines for choosing:

  • Strengthening data augmentation as training progresses, or searching for a policy on one's own data: Use PBA. It can find a schedule in a few GPU hours.
  • Eliminating the search stage itself: Use RandAugment or TrivialAugment. They take little tuning effort and reach about the same accuracy.
  • Using a published policy as is: For data similar to CIFAR, SVHN, or ImageNet, AutoAugment's policies (torchvision's AutoAugment) are convenient.

PyTorch example

Show code
python
import random

# A small implementation of the PBA policy (Algorithm 1) and explore (Algorithm 2).
# The search itself (parallel training of 16 child models and exploit) is left to a PBT implementation such as Ray Tune's PopulationBasedTraining.

OPS = ["AutoContrast", "Equalize", "Invert", "Rotate", "Posterize", "Solarize", "Color", "Contrast",
       "Brightness", "Sharpness", "ShearX", "ShearY", "TranslateX", "TranslateY", "Cutout"]   # 15 operations
PROBS = [i / 10 for i in range(11)]    # 0-100% in steps of 10%
MAGS = list(range(10))                  # magnitude 0-9


def init_policy():
    """30 entries [operation, probability index, magnitude], each operation twice. As in the paper, all start at 0."""
    return [[op, 0, 0] for op in OPS for _ in range(2)]


def apply_policy(img, policy, op_fns):
    """Algorithm 1: in shuffled order, apply operations selected by probability, up to count times.

    op_fns: operation name -> function f(img, mag). Prepare with PIL image operations, etc.
    """
    count = random.choices([0, 1, 2], weights=[0.2, 0.3, 0.5])[0]
    for op, p_idx, mag in random.sample(policy, len(policy)):
        if count == 0:
            break
        if random.random() < PROBS[p_idx]:
            count -= 1
            img = op_fns[op](img, mag)
    return img


def explore(policy):
    """Algorithm 2: resample each value uniformly with probability 0.2; otherwise shift it by 0-3 steps and clamp to the range."""
    new = []
    for op, p_idx, mag in policy:
        values = []
        for v, n in ((p_idx, len(PROBS)), (mag, len(MAGS))):
            if random.random() < 0.2:
                v = random.randrange(n)
            else:
                amt = random.choice([0, 1, 2, 3])
                v = v + amt if random.random() < 0.5 else v - amt
                v = min(max(v, 0), n - 1)
            values.append(v)
        new.append([op, *values])
    return new


# One PBT exploit-and-explore step (every 3 epochs):
#   child models in the bottom 25% copy the weights and policy of a top-25% child model, then set policy = explore(policy).
# The record of the policy at each epoch is the "policy schedule"; final training uses schedule[t] at epoch t.

FAQ

Q. Why is it so much faster than AutoAugment?
A.

AutoAugment retrains a child model for 120 epochs for each of about 15,000 policies. PBA trains 16 child models only once, changing the policy along the way while copying the weights and policies of the better-performing models. The total number of training epochs drops from about 1.8 million to 3,200, and the CIFAR-10 search went from 5,000 GPU hours to 5 GPU hours.

Q. Is it fine to use only the last policy of the schedule found?
A.

In the paper's comparison, fixing the last policy worsened the CIFAR-10 (Wide-ResNet-28-10) error rate from 2.58% to 2.76%. The change over time, applying augmentation gently early in training and strongly later, is what helps, so the standard practice is to use the schedule as is.

Q. How do PBA and PBT differ?
A.

PBT is a general-purpose search method that tunes hyperparameters during training. PBA treats the data augmentation policy (the probability and magnitude of each operation) as hyperparameters searched by PBT, and uses only the resulting hyperparameter schedule to train a different model.

References

  1. Ho, D., Liang, E., Stoica, I., Abbeel, P., & Chen, X. (2019). Population Based Augmentation: Efficient Learning of Augmentation Policy Schedules. ICML 2019.
  2. Jaderberg, M., et al. (2017). Population Based Training of Neural Networks. arXiv:1711.09846.
  3. Official PBA implementation (arcelien/pba)