Skip to content
Back to skills

Test Time Augmentation

ASecurity

Applies geometric and color augmentations at inference time and averages predictions to reduce variance.

  • 61 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added September 12, 2026
toolspython

Security analysis

A100/100

Scanned September 12, 2026

npx -y skills add wenmin-wu/ds-skills --skill test-time-augmentation --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Test Time Augmentation?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Test Time Augmentation
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/wenmin-wu-test-time-augmentation/badge)](https://www.skillsdirectory.com/skills/wenmin-wu-test-time-augmentation)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: cv-test-time-augmentation
description: >
  Applies geometric and color augmentations at inference time and averages predictions to reduce variance.
---
# Test-Time Augmentation (TTA)

## Overview

Generate multiple augmented copies of each input image at inference (flips, 90-degree rotations, brightness/contrast jitter), run the model on all copies, then average the predictions. Reduces prediction variance and improves robustness without retraining.

## Quick Start

```python
import numpy as np

def tta_predict(model, image, n_augments=8):
    preds = []
    for _ in range(n_augments):
        aug = apply_random_augment(image)  # flip, rotate, color jitter
        preds.append(model.predict(aug[np.newaxis]))
    return np.mean(preds, axis=0)

def apply_random_augment(img):
    if np.random.rand() > 0.5:
        img = np.fliplr(img)
    if np.random.rand() > 0.5:
        img = np.flipud(img)
    k = np.random.randint(0, 4)
    img = np.rot90(img, k)
    return img
```

## Workflow

1. Define augmentation set (flips, rotations, color transforms)
2. For each test image, generate N augmented copies
3. Run model inference on all copies
4. Average (classification) or geometrically reverse + average (segmentation) predictions
5. Use averaged prediction as final output

## Key Decisions

- **N augments**: 4-8 is typical; diminishing returns beyond 16
- **Augment types**: Match training augmentations for best effect
- **Segmentation TTA**: Must reverse spatial transforms before averaging masks
- **Cost**: Inference time scales linearly with N; batch augmented copies for GPU efficiency

## References

- HPA Single Cell Classification competition (Kaggle)
- Source: [hpa-cellwise-classification-inference](https://www.kaggle.com/code/dschettler8845/hpa-cellwise-classification-inference)

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…