BNNR

Playground

Explore every BNNR augmentation visually — including XAI-driven ICD and AICD — then grab ready-to-run code templates.


Code Playground

Copy-paste ready templates for every BNNR workflow. Each example is self-contained and runnable as-is.

Full classification pipeline with XAI explainability. Trains a baseline, then iteratively searches for the best augmentation stack.

# pip install "bnnr[dashboard]"
from bnnr import quick_run, BNNRConfig

import torch.nn as nn

model = nn.Sequential(
    nn.Conv2d(3, 32, 3, padding=1),
    nn.BatchNorm2d(32),
    nn.ReLU(),
    nn.AdaptiveAvgPool2d(1),
    nn.Flatten(),
    nn.Linear(32, 10),
)

from torchvision import datasets, transforms
from torch.utils.data import DataLoader

transform = transforms.Compose([
    transforms.Resize(96),
    transforms.ToTensor(),   # [0, 1] range — do NOT normalize
])
train_ds = datasets.STL10("data", split="train", download=True, transform=transform)
val_ds   = datasets.STL10("data", split="test",  download=True, transform=transform)
train_loader = DataLoader(train_ds, batch_size=64, shuffle=True)
val_loader   = DataLoader(val_ds,   batch_size=64)

result = quick_run(
    model, train_loader, val_loader,
    config=BNNRConfig(
        m_epochs=5,
        max_iterations=3,
        device="auto",
        xai_enabled=True,
        report_preview_size=512,
        report_xai_size=512,
    )
)

print(f"Best accuracy: {result.best_metrics}")
print(f"Aug path:      {result.best_path}")