--- license: cc-by-4.0 library_name: pytorch tags: - domain-adaptation - few-shot - image-classification - next-lab --- ![shift](https://cdn-uploads.huggingface.co/production/uploads/67d46bc5fe6ad6f6511d6f44/HJchr60Q9AcTZb_zL9p3S.png) # Next Shift Next Shift adapts a digit recogniser trained on clean scans to a **new visual environment** (grey, low-contrast, textured, rotated, blurred captures) using only a handful of labeled target images. It first re-estimates BatchNorm statistics on unlabeled target images (AdaBN), then fine-tunes the top MLP on the labels. The target environment is a **synthetic** transform of real UCI digits. **Space:** https://huggingface.co/spaces/thelamapi/Next-Shift — label a few target images; the top layers fine-tune in your browser and predictions update. ## Results: target test accuracy (297 images, 5 seeds, mean ± std) | Method | k=0 | k=1 | k=5 | k=10 (labels per class) | |---|---:|---:|---:|---:| | Next Shift (AdaBN + fine-tune top) | 0.394 ± 0.000 | 0.489 ± 0.033 | 0.588 ± 0.021 | 0.661 ± 0.010 | | Ablation: fine-tune top, no AdaBN | 0.401 ± 0.000 | 0.459 ± 0.042 | 0.589 ± 0.014 | 0.673 ± 0.009 | | Frozen source features + linear head | 0.401 ± 0.000 | 0.358 ± 0.031 | 0.558 ± 0.019 | 0.613 ± 0.022 | | Random init, same labels and steps | 0.099 ± 0.023 | 0.211 ± 0.022 | 0.467 ± 0.026 | 0.636 ± 0.050 | Source-only accuracy on the source validation split: 0.973; on the target test split: 0.401. For each k and seed, every method sees the same labeled images. Steps and learning rates were chosen per method on a separate 100-image target development split (seeds 100–102), never on the test split. ![Accuracy vs labels](preview.png) ## Method * Encoder: 2 conv blocks (16, 32 channels, BatchNorm, ReLU, max-pool) → 512 features → fc 64 → 10 classes; pre-trained on 900 source images. * Next Shift: AdaBN on 350 unlabeled target pool images, then 50 full-batch GD steps (lr 0.05) on the top MLP. * Frozen representation: linear head on fixed 64-d source features (200 steps, lr 0.1). * Random init: the whole network from scratch with Adam (100 steps, lr 0.001). * Ablation without AdaBN: same fine-tuning on source-normalised features. * Browser: conv stacks run through `nlrt.js` and the fine-tuning is a line-by-line port; Node parity max abs difference 5.412337245047638e-16. ## Usage ```python from inference import load, adapt, predict spec = load() # NumPy only top = adapt(spec, target_images, labels) # images: (N,16,16) in [0,1] probs = predict(spec, new_images, top) ``` `source_model.safetensors` holds the PyTorch source weights (architecture in the notebook). ## Limitations * The domain shift is synthetic and the images are tiny; real shifts (sensors, lighting, populations) can be harder. * AdaBN needs a batch of unlabeled target images; the released `conv_target` was estimated on the target pool. * 96 of 297 target test images are still wrong for Next Shift at k=10 (seed 0); see `evaluation.json`. * Trained on NVIDIA L4; profile full.