wikillm

Paper · 2023-08-08 · cs.CV, cs.LG

From Fake to Real: Pretraining on Balanced Synthetic Images to Prevent Spurious Correlations in Image Recognition

FFR pretrains a ResNet-50 on class-balanced Stable Diffusion images, then fine-tunes on real data with ERM or a bias-mitigation loss, so real and synthetic images never share a step. Author-reported: CelebA-HQ worst-group accuracy averaged over bias ratios rises from 58.9 to 82.3, and the paper claims gains of up to 20 points over the state of the art.

Data augmentationData resampling for class imbalanceDiffusion modelsAlgorithmic fairnessspurious-correlationssynthetic-databias-mitigationworst-group-accuracydata-balancing

arXivPDFCodeMarkdown11 min read

AI-compiled by claude-haiku-5-5 on 2026-11-09, not yet reviewed by a human. Every claim cites its source; check it when a detail matters.

In plain words

Image classifiers often learn shortcuts. If most training photos of big dogs show them indoors, a model can learn "indoors" instead of "big dog", and then fail on a big dog outdoors. A common fix is to add generated images for the rare combinations. This paper shows that mixing generated and real images in one training run can create a new shortcut: the model can learn to tell real from generated images and pair that difference with the label.

The proposed fix, From Fake to Real, splits training into two stages. First the model sees only generated images, with the same number for every combination of class and context. Then it is fine-tuned on the real photos, either with ordinary training or with a method designed for uneven groups. The model never sees real and generated images in the same training step.

The authors test this on three datasets of faces and animals, at several levels of imbalance, and report better worst-group accuracy than mixing the two kinds of data. These results are the authors' own.

TL;DR

  • Balancing a biased dataset with generated images can make the model rely on a real-versus-generated cue together with the bias. The paper proves that some such bias always remains when the two sources are mixed §3.1 app. A.
  • FFR avoids the mix: stage 1 trains on balanced synthetic data only, and stage 2 fine-tunes on real data §3.2.
  • Author-reported gains over prior synthetic-balancing methods (USB, ASB) in worst-group accuracy; the largest gains are at high bias §4.1 tab. 4 fig. 3.
  • The code is public but has no licence file, so only pseudocode and citations are safe to reuse. Several settings differ between paper and code (see Paper vs code).

Problem

A dataset is biased when the bias variable B, such as gender or background, is unevenly spread over classes Y, so that P(Y | B) differs from P(Y) §1 §3. A model trained on it can predict Y from B. Worst-group accuracy, the accuracy of the worst (class, bias) subgroup, measures this failure §4.

Prior fixes add generated images to make the data balanced. The paper argues that any such augmentation keeps a bias toward the pair (B, G), where G says whether an image is real or generated. Theorem 1 states that, for every augmented version of the dataset, P(Y | B, G) differs from P(Y) §3.1 app. A. The assumption is that generated and real images differ in distribution, as in generator artefacts §1 §3.1. The theorem is a claim about the augmented data, not a bound on test error.

Method

Motivation. The paper studies two prior augmentation schemes. Additive Synthetic Balancing (ASB) adds a balanced synthetic set to the real data. Uniform Synthetic Balancing (USB) adds enough synthetic images to equalise all subgroups §3.1 §4. Both train on real and synthetic images together. The paper's illustration is that USB can push a model toward (Water, Synthetic) cues when real and synthetic groups are unequal §3.1.

Step 1: synthetic pretraining. Generate images with a text-to-image model, using the bias and the class in the prompt, so that each (class, bias) group gets the same number of images. The total count equals the number of images USB would need to balance the real data §3.2 §4. Train a ResNet-50 with ERM on these images only, starting from ImageNet weights §4 app. E. The paper calls the result the stage-1 model §3.2.

Step 2: real fine-tuning. Initialise from the stage-1 model and fine-tune on the biased real training set. The paper uses ERM or a loss-based bias-mitigation method, and reports GroupDRO, Resampling and DFR as step-2 options §3.2 §4. The paper reports that the stage-1 start helps for every step-2 method §3.2. Freezing batch-norm during step 2 helped on some settings; the choice is a per-setting hyperparameter §4 app. E.

Why the order matters. Reversing the stages, or pretraining on a biased synthetic distribution, gives lower worst-group accuracy in the paper's ablations §4.3 tab. 1 tab. 2.

Pseudocode
# FFR with ERM: stage 1 on synthetic images, stage 2 on real images  [§3.2]
# Input:  synthetic_set: equal count per (class, bias) group  [§4]
#         real_train_set: biased real training data  [§4]
#         real_val_set: real validation data with bias labels  [§4] [app. E]
# Output: model fine-tuned on real data

def ffr_erm(synthetic_set, real_train_set, real_val_set):
    # Stage 1: ImageNet ResNet-50, ERM on synthetic images only  [§3.2]
    model = resnet50_imagenet()
    model = train_erm(model, synthetic_set, real_val_set, lr_stage_1)
    # Stage 2: start from all stage-1 weights, classifier head included
    # (the code does not re-initialise the head)  [code: trainer.py#L31-L34]
    model = train_erm(model, real_train_set, real_val_set, lr_stage_2)
    return model
Pseudocode
# ERM loop with checkpoint choice by worst-group validation accuracy
# Input:  model, train_set, val_set, lr
# Output: best checkpoint over epochs

def train_erm(model, train_set, val_set, lr):
    # Adam with weight decay 1e-5  [app. E]
    optimizer = adam(model.parameters(), lr=lr, weight_decay=1e-5)
    # 20 epochs  [app. E]
    best_model = None
    best_worst = -infinity
    for epoch in range(20):
        # Batch size 128 is the code default; the paper does not state it
        # [code: training_code/train_erm_ffr_1.py#L124]
        for images, labels in batches(train_set, batch_size=128):
            loss = cross_entropy(model(images), labels)
            optimizer.zero_grad()
            loss.backward()
            optimizer.step()
        # Keep the epoch with the best worst-group validation accuracy
        # [code: training_code/train_erm_ffr_1.py#L92-L99] [code: trainer.py#L85]
        worst = worst_group_accuracy(model, val_set)
        if worst > best_worst:
            best_worst = worst
            best_model = copy_of(model)
    return best_model

Synthetic data. The generator is Stable Diffusion v1.4 §4. Prompts take the form "A photo of {bias} {class}" §4. The released scripts use different prompts per dataset; see Paper vs code. Each generated image is labelled with its class and bias, and the generated set is subsampled to the balanced size §4 dataset.py.

Corruption study. To test lower-quality generators, the paper applies pixelate, defocus blur and Gaussian noise from Michaelis et al. at severity 0 and 5 app. B tab. 4.

Hyperparameters

NameValueWhereNotes
BackboneResNet-50, ImageNet-pretrained§4 app. ECode uses torchvision weights utils.py
OptimiserAdam; other parameters default§4Code uses torch Adam with weight decay trainer.py
Learning rate grid1e-4, 1e-5, 1e-6, 1e-7app. EGrid search on validation. The FFR rows of the table reach 1e-8 and 1e-9, which are outside this grid tab. 6
FFR learning rates1e-4 to 1e-9 across settingstab. 6The table does not say which stage the FFR rows describe
Stage-1 learning ratenot statedapp. ECode default 1e-4 train_erm_ffr_1.py; no grid script in repo
Stage-2 learning ratenot stated per settingapp. ECode default 1e-3 train_erm_ffr_2.py, outside the paper's grid
Weight decay1e-5app. EThe sentence in the paper is garbled ("for UTK-Face, CelebA-HQ for SpuCo Animals"); code default is 1e-5 for all three datasets train_erm_ffr_1.py
Epochs20app. ECode default is 50 train_erm_ffr_1.py
Batch sizenot statedapp. ECode default 128 train_erm_ffr_1.py
Batch norm in stage 2frozen or not, per setting§4 app. E tab. 7Code freezes it with model.eval() train_erm_ffr_2.py
Validation group sizeat least 10 samples per groupapp. EConsistent with code: make_harder keeps at least 10 on the validation split spuco_animals.py
Input size224 x 224, ImageNet normalisation, no augmentationnot stated in paperCode: train_erm_ffr_1.py; horizontal flip is commented out
Synthetic countequal per group, total = USB balancing count§4Code uses floor(total / 4) per group train_erm_ffr_1.py
Synthetic prompt"A photo of {bias} {class}"§4Released scripts differ; see Paper vs code
Corruptionpixelate, defocus blur, Gaussian noiseapp. BSame three in code at equal severity dataset_gen.py

Results

Author-reported. Setup: ResNet-50; CelebA-HQ (target Smiling, bias Gender), UTK-Face (target Gender, bias Age) and SpuCo Animals (target dog or bird, bias background); bias ratios 90 to 99.9 percent, with SpuCo Animals starting at 95 percent §4 app. E. Baselines are no synthetic data, USB and ASB. "WA" is worst-group accuracy and "BA" is balanced accuracy §4. Table headers call BA "BC" in tables 4, 5 and 8. The "±" values are not defined in the text, and the number of seeds is not stated.

SettingMetricBaselineThis paperSource
CelebA-HQ, ERM, average over five bias ratiosWA58.9 (no synthetic data)82.3 (FFR, balanced pretraining)tab. 2
CelebA-HQ, sameBA81.288.6tab. 2
CelebA-HQ, same, biased pretraining insteadWA69.682.3tab. 2
SpuCo Animals, average over ratios, stage ablationWA30.6 (stage 2 only)72.6 (stage 1 to stage 2, FFR)tab. 1
SpuCo Animals, sameBA68.1 (stage 2 only)83.4tab. 1
SpuCo Animals, real test data, average over ratiosWA59.5 (USB), 48.9 (ASB)72.6tab. 3
CelebA-HQ, ViT-32 backbone app. FWA64.9 (USB), 60.1 (ASB), 54.2 (none)82.8tab. 8
CelebA-HQ, ViT-32 backbone app. FBA82.1 (USB), 81.1 (ASB), 78.9 (none)87.7tab. 8
UTK-Face, average over five ratios, severity 0 to 5WAUSB 36.5 to 29.5; ASB 40.2 to 32.9FFR 56.2 to 50.6tab. 4
CelebA-HQ, bias-agnostic versus bias-aware promptWA77.6 (agnostic)82.3 (aware)tab. 5 app. D
Three datasets and five ratios, Figure 4 row 1 (no synthetic-free method)WAnot stated in text70.3 (FFR)§4.2 fig. 4
Headline claimWAup to 20 points over state of the art-§1 fig. 3

Text results. On UTK-Face at 95 percent bias, the paper says FFR improves over USB and ASB "by over 10%" (the unit is not defined) §4.1. Averaged over datasets and ratios, using FFR as the synthetic-augmentation step raises worst accuracy of Resampling and GroupDRO by 13 percent each and of DFR by 4 percent, the paper's wording §4.2. The per-cell numbers behind fig. 3 are only in the figure, not in the text.

Paper vs code

The official repository is mqraitem/From-Fake-to-Real (owner is the first author). It has no LICENSE file, so no code is copied verbatim here.

Pitfalls

  • "Balanced" is a count, not a ratio. Stage 1 needs the same number of images in every (class, bias) group, and the total should match the USB top-up. Whether the top-up uses the real training groups after subsampling to the target ratio is a code detail dataset.py, not stated in the paper.
  • Checkpoints are chosen on real validation data with bias labels. Stage 1 never sees real images, yet its checkpoint, and the stage-1 hyperparameter, is chosen with real validation worst-group accuracy trainer.py. A replication that tunes on test data would overstate results.
  • Stage 2 can relearn the bias. The paper says the real data's bias can come back during fine-tuning, and that loss-based methods are added for this reason §3.2. Ablation: stage 2 alone reaches 30.6 WA, against 72.6 for FFR tab. 1.
  • Prompt quality matters. Dropping the bias term from the generator prompt lowers CelebA-HQ FFR WA from 82.3 to 77.6. The authors attribute this to the generator's own gender imbalance app. D tab. 5.
  • Generator quality matters, but FFR degrades less. At severity 5 on UTK-Face, FFR WA falls from 56.2 to 50.6, while USB and ASB fall more tab. 4 app. B.
  • Batch-norm freezing is not fully specified. The paper says only "freeze"; the code also leaves BN affine parameters trainable train_erm_ffr_2.py.
  • Cost. Each FFR result needs a stage-1 run for every stage-1 hyperparameter setting, then a stage-2 search over learning rates and batch-norm options, averaged over seeds trainer.py. The paper reports over 5k experiments in total §1.
  • Theorem 1 is a statement about the augmented dataset. It does not say FFR removes all bias; the claim for FFR is empirical §4.4 fig. 5.
  • Cross-reference error. Section 4.5 cites Figure 5 for the saliency maps, but the saliency figure is Figure 6 in the source (label fig:figure_6); Figure 5 is the t-SNE plot §4.4 §4.5 fig. 5 fig. 6.
  • Table numbers. Tables are numbered here in LaTeX source order. Check them against the PDF before citing.
  • Headline gain. "Up to 20%" §1 is not tied to a setting in the text. The per-cell values are only in fig. 3.
  • Unexplained spread. The "±" values have no definition and the number of seeds is not stated, so intervals cannot be compared with other papers.

Lineage

  • Builds on: Additive Synthetic Balancing (ASB), Ramaswamy et al., CVPR 2021; and Uniform Synthetic Balancing (USB), Mondal et al. (AISTATS). FFR changes these by separating the two data sources into two training stages §3.1 §4.
  • Stage-2 options: ERM, GroupDRO (Sagawa et al., ICLR 2020), Resampling, and Deep Feature Reweighting (Kirichenko et al., ICLR) §3.2 §4.
  • Background: Corvi et al. (ICASSP 2023) on synthetic-image artefacts, and Sariyildiz et al. on the real-to-synthetic distribution shift §1 §3.2.
  • Compared against: no synthetic data, USB, ASB; in the appendix, a ViT-32 backbone app. F tab. 8.
  • Superseded by: not stated.

Source and license

Adapted from “From Fake to Real: Pretraining on Balanced Synthetic Images to Prevent Spurious Correlations in Image Recognition” by Maan Qraitem, Kate Saenko, Bryan A. Plummer (arXiv:2308.04553), used under CC BY 4.0. Changes: condensed and restructured for implementation, with tables, equations and algorithms taken from the paper and its code, each cited to its source. Not affiliated with or endorsed by the authors. Code citations refer to https://github.com/mqraitem/From-Fake-to-Real at commit cd4d1533cf0f (none (no LICENSE file in repository)). Any quoted code is shown under that license.