Add model card
Browse files
README.md
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: other
|
| 3 |
+
tags:
|
| 4 |
+
- change-detection
|
| 5 |
+
- object-detection
|
| 6 |
+
- document-analysis
|
| 7 |
+
- centernet
|
| 8 |
+
- siamese
|
| 9 |
+
library_name: pytorch
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
# CyberAI Cup 2026 β Task 1: Packaging Material Difference Mining
|
| 13 |
+
|
| 14 |
+
Complete working state of the solution: trained weights, all source code, documentation, and the raw
|
| 15 |
+
evidence behind every reported number. Private repository β this is a working handover, not a release.
|
| 16 |
+
|
| 17 |
+
## Current result
|
| 18 |
+
|
| 19 |
+
Fold-0 out-of-fold **global F1 0.9049** (precision 0.9225, recall 0.8881, score threshold 0.31),
|
| 20 |
+
measured on 40 held-out validation pairs with the competition's own metric: TP/FP/FN accumulated
|
| 21 |
+
across all images before computing precision and recall, boxes matched at IoU β₯ 0.5.
|
| 22 |
+
|
| 23 |
+
For scale, the classical image-difference baseline scores **0.029** on the same split.
|
| 24 |
+
|
| 25 |
+
Folds 1β4 are untrained and no submission has been generated. `HANDOVER.md` section 5 holds the
|
| 26 |
+
prioritized queue for whoever continues.
|
| 27 |
+
|
| 28 |
+
## What is in here
|
| 29 |
+
|
| 30 |
+
| Path | Contents |
|
| 31 |
+
|---|---|
|
| 32 |
+
| `checkpoints/stage1_fold0_convnext_tiny/best.pt` | The model β 128 MB, epoch 19, the 0.9049 checkpoint |
|
| 33 |
+
| `checkpoints/stage1_fold0_convnext_tiny/last.pt` | 384 MB, epoch 35, with optimizer and scheduler state for resuming |
|
| 34 |
+
| `checkpoints/oof/` | Out-of-fold candidate boxes and the threshold sweep |
|
| 35 |
+
| `checkpoints/stage2_ab/` | Verifier from the A/B test β reference only, its measured delta was +0.0009 |
|
| 36 |
+
| `src/pmdm/` | 14 modules, ~1500 lines: preprocessing, model, losses, decoding, training, inference, metric |
|
| 37 |
+
| `modal_app.py` | Every Modal function and entrypoint used to produce these results |
|
| 38 |
+
| `scripts/` | CPU smoke test, local training without Modal, dataset analysis, error analysis |
|
| 39 |
+
| `runs/` | Raw training logs, per-epoch history, and analysis output from every run |
|
| 40 |
+
| `Task1/` | The competition dataset: 200 training pairs with 1407 annotated boxes, 100 test pairs |
|
| 41 |
+
| `HANDOVER.md` | Start here β architecture, results, error breakdown, mistakes, next steps |
|
| 42 |
+
| `RUNBOOK.md` | Every command with measured timings |
|
| 43 |
+
| `IMPLEMENTATION_PLAN.md` | Original design rationale |
|
| 44 |
+
|
| 45 |
+
## Architecture
|
| 46 |
+
|
| 47 |
+
A siamese CenterNet. Both images pass through a shared ConvNeXt-tiny encoder taking 4 channels
|
| 48 |
+
(BGR plus a local-background-normalized "ink map" that makes the features invariant to the photo's
|
| 49 |
+
shadows). Features fuse per scale as `conv(concat(a, b, |a β b|))`, decode through a U-Net upsampling
|
| 50 |
+
path, and emit four heads at **output stride 2** β a Gaussian focal heatmap for difference centers,
|
| 51 |
+
width/height, a sub-pixel offset, and an auxiliary change-mask segmentation.
|
| 52 |
+
|
| 53 |
+
Stride 2 is the load-bearing choice: 83 of the ground-truth boxes are 8Γ8 pixels, which vanish
|
| 54 |
+
entirely at the stride 4 a standard CenterNet uses.
|
| 55 |
+
|
| 56 |
+
Three things about the data drove the rest of the design:
|
| 57 |
+
|
| 58 |
+
1. **Pairs are already sub-pixel aligned.** Of 300 pairs, 284 need no registration at all and 16 need
|
| 59 |
+
a pure translation. No warping is applied by default.
|
| 60 |
+
2. **Blur, not geometry, is the dominant false-positive source.** The photo is softer than the
|
| 61 |
+
template, so the template is blur-matched to it with a Ο grid search minimizing the
|
| 62 |
+
Laplacian-variance gap before any comparison.
|
| 63 |
+
3. **Nothing is ever deleted.** Of 1404 analysed boxes, 842 are additions and 558 are modifications
|
| 64 |
+
of existing content β and exactly 0 are deletions. That licenses a polarity filter discarding any
|
| 65 |
+
candidate that is inked in the template and blank in the photo.
|
| 66 |
+
|
| 67 |
+
Inference tiles each page at 768 px with 25% overlap, then merges candidates with Weighted Boxes
|
| 68 |
+
Fusion rather than NMS β with boxes this small, averaging the coordinates beats picking one.
|
| 69 |
+
|
| 70 |
+
## Loading the model
|
| 71 |
+
|
| 72 |
+
```python
|
| 73 |
+
import torch
|
| 74 |
+
from pmdm.model import SiamCenterNet
|
| 75 |
+
|
| 76 |
+
model = SiamCenterNet(backbone="convnext_tiny")
|
| 77 |
+
ck = torch.load("checkpoints/stage1_fold0_convnext_tiny/best.pt", map_location="cpu")
|
| 78 |
+
model.load_state_dict(ck["model"]) # all keys match
|
| 79 |
+
model.eval()
|
| 80 |
+
```
|
| 81 |
+
|
| 82 |
+
`ck["metric"]` carries the evaluation that selected this checkpoint, including the 0.31 threshold.
|
| 83 |
+
Full tiled inference over a page is `pmdm.infer`; scoring is `pmdm.metric.global_f1`.
|
| 84 |
+
|
| 85 |
+
## Reproducing
|
| 86 |
+
|
| 87 |
+
```bash
|
| 88 |
+
uv venv --python 3.12 .venv
|
| 89 |
+
uv pip install --python .venv/bin/python -e . torch torchvision timm \
|
| 90 |
+
opencv-python-headless "numpy<2" pandas
|
| 91 |
+
|
| 92 |
+
# CPU pre-flight over the whole pipeline, ~2 min
|
| 93 |
+
PMDM_DATA=Task1/PackagingMaterialDifferenceMiningDataset \
|
| 94 |
+
PMDM_WORK=/tmp/pmdm_work PMDM_CKPT=/tmp/pmdm_ckpt \
|
| 95 |
+
.venv/bin/python scripts/local_smoke.py
|
| 96 |
+
|
| 97 |
+
# every dataset claim above
|
| 98 |
+
PMDM_DATA=Task1/PackagingMaterialDifferenceMiningDataset \
|
| 99 |
+
.venv/bin/python scripts/analyze_dataset.py
|
| 100 |
+
|
| 101 |
+
# the error breakdown, from the archived out-of-fold predictions
|
| 102 |
+
.venv/bin/python scripts/error_analysis.py checkpoints/oof/fold0_convnext_tiny.npz
|
| 103 |
+
```
|
| 104 |
+
|
| 105 |
+
Training runs either on Modal (`modal run --detach modal_app.py::train --fold 0 --epochs 40`,
|
| 106 |
+
~45 min on an A100-40GB) or on any GPU box with no Modal account
|
| 107 |
+
(`python scripts/train_local.py --fold 0 --epochs 40`). Same loop, same checkpoints.
|
| 108 |
+
|
| 109 |
+
## Where the remaining errors are
|
| 110 |
+
|
| 111 |
+
Of 268 ground-truth boxes across the validation fold: 252 were proposed and matched, 5 were proposed
|
| 112 |
+
but localized too loosely to clear IoU 0.5, and 11 were never proposed at all β a recall ceiling of
|
| 113 |
+
0.959 for the current proposal stage.
|
| 114 |
+
|
| 115 |
+
By box size, the picture is lopsided: boxes above 24 px match 97.5% of the time, 12β24 px match
|
| 116 |
+
97.9%, and boxes under 12 px match 82.8%. **Ten of the eleven complete misses are sub-12px marks.**
|
| 117 |
+
Everything else is solved. That is why the next step is synthetic data weighted toward tiny marks
|
| 118 |
+
(`src/pmdm/synth.py`, written and smoke-tested but never run at scale) rather than more box
|
| 119 |
+
refinement or a stronger verifier.
|
| 120 |
+
|
| 121 |
+
## License
|
| 122 |
+
|
| 123 |
+
The dataset in `Task1/` belongs to the CyberAI Cup 2026 organizers and is included here only so this
|
| 124 |
+
private repository is self-contained for the team. Do not redistribute it.
|