--- license: apache-2.0 language: - en - zh base_model: Roboflow/rf-detr-large pipeline_tag: object-detection library_name: torch tags: - pcb - defect-detection - rfdetr - small-object-detection - dspcbsd - industrial-inspection --- # BoardEye — RF-DETR-L for PCB surface-defect detection (9 classes) Weights only. [RF-DETR-Large](https://huggingface.co/Roboflow/rf-detr-large) (Roboflow; Robinson et al., *RF-DETR: Neural Architecture Search for Real-Time Detection Transformers*, arXiv:2511.09554, accepted at ICLR 2026) fine-tuned on **DsPCBSD+** — 9 classes of printed-circuit-board surface defects, trained at 640 px and inferring at the Large preset of 704 × 704 (see "Browser-side ONNX export" below). The training/evaluation version **1.8.3 is an author record**: the only machine-readable version evidence shipped here is the **inference-side** pin `rfdetr==1.8.3` (`inference/infer/requirements.txt`), while the training-side `requirements.txt` sets only a `>=1.8.0` floor. The packaged `training_config.json` identifies the run (`output_dir` → `rfdetr_l_640_v11a_lrl`, `resume` from the v9 best-EMA checkpoint) but contains **no package-version field at all**, so reproducibility rests on the inference lock plus an author-side record, not on a training manifest. Industrial-optical-inspection research; not a validated production AOI system. **Bilingual results board (free Static Space)** — headline metrics, per-class AP, the class-frequency inversion, ceiling probes and the eleven archived paths: . 靜態中英結果板(免費 Static Space):託管於同連結,不需任何訂閱即可開。 **Interactive demo, inference in your own browser** — runs the `model.onnx` shipped in this repo through onnxruntime-web (WebGPU first, WASM fallback), so uploaded images never leave the visitor's device and no server GPU is involved. 瀏覽器端互動 Demo:同一份 ONNX 跑在訪客自己的瀏覽器裡,影像不上傳、沒有佇列與伺服器成本;免費 Static Space 即可托管(免費帳號要建立 Python 容器 Space 會得到 `402 Payment Required`)。 ## Headline result | Metric | Value | What it is | |---|---|---| | **mAP@0.5:0.95** | **0.5397** | independent end-to-end `pycocotools` re-evaluation of `checkpoint_best_ema.pth`, 3 seeds (0/1/2) with `cudnn.deterministic` | | mAP@0.5 | 0.8677 | same run | | mAP@0.75 | 0.5710 | same run(與倉內 `class_names.json` 一致;舊版卡片誤植 0.5715)| | mAP@0.5:0.95 (log peak) | 0.5411 | trainer-recorded EMA at epoch 9 of run `rfdetr_l_640_v11a_lrl` (`metrics.csv`) — a training-log value, not a re-evaluation | `std = 0.0` and `CI95 = 0.0` across the three seeds come from evaluation-side determinism (fixed seeds, deterministic cuDNN), **not** from model stability. The per-image `eval_results.json` was not preserved, so 0.5397 is verified at the aggregate level only. ## Per-class AP@0.5:0.95 (aggregate eval record) | Class | AP | Class | AP | Class | AP | |---|---|---|---|---|---| | HB (hole breakout) | 0.8321 | OP (open circuit) | 0.5623 | SC (short circuit) | 0.5446 | | SH (solder hole) | 0.5805 | BMFO (burnt mark / fake open) | 0.5006 | CS (copper splash) | 0.5167 | | MB (mouse bite) | 0.4276 | CFO (conducting filament) | 0.4868 | SP (spurious copper) | 0.4025 | Median box width is ~21 px in a 226×226 source image, so this is a small-object task; that geometry, not the detector choice, is what caps mAP@0.5:0.95. The box-size statistic is an author record — per-image annotation arrays are not shipped — while the shipped evidence for the small-object bottleneck is `class_names.json` (`AP_small = 0.4563` versus `AP_large = 0.7386`). ## Training recipe (from the packaged `training_config.json`) ``` run rfdetr_l_640_v11a_lrl input 640 epochs 11 (resumed) lr 5e-5 steps / epoch 748 dataset_file roboflow (COCO layout) resume v9 checkpoint_best_ema.pth weights only (bf16 + fused-Adam dtype incompatibility) package rfdetr==1.8.3 (Apache-2.0) [author record — that version is NOT a field in this config] ``` Relay chain: **v8 → v9 → v11a** (three stages, ten logged epochs; this checkpoint is the third stage, resumed from v9). Total gain of that final stage over v9 is **+0.0008 mAP**; the real jumps came from switching to RF-DETR-L at 640 px and from fixing a COCO `file_name` prefix bug (`file_name` must be `images/`), not from the lower learning rate. The repository keeps **thirteen archived preliminary probes** (`docs/notes/02-archived-directions.md`), eleven of them tabled in `docs/results.md` §4.3 — the two extra being early RF-DETR runs stopped before convergence. Their figures are author records and are **not** verified numbers here: the run directories are absent. ## Files here | File | Size | Notes | |---|---|---| | `checkpoint_best_ema.pth` | 128.05 MB | EMA weights of run v11a (the checkpoint that produced 0.5397) | | `training_config.json` | — | full hyper-parameters as written by the trainer | | `metrics.csv` | — | per-epoch raw/EMA metrics for v11a epochs 8–10 | | `model.onnx` | 121,612,490 B | fp32 export of the same checkpoint, opset 17, static input `[1,3,704,704]`; powers the browser-side demo | | `SHA256SUMS.txt` | — | checksums for the files above (`.pth`, `.onnx`, config, metrics) | ## Usage ```bash pip install "rfdetr==1.8.3" ``` ```python from rfdetr import RFDETRLarge model = RFDETRLarge(pretrain_weights="checkpoint_best_ema.pth") dets = model.detect("pcb_tile.jpg", threshold=0.3) ``` Class order and the inference wrapper (incl. tiling, which was tested and **rejected** — SAHI slicing cost −23% mAP) live in **[github.com/NextBai/boardeye](https://github.com/NextBai/boardeye)** — 27 passing tests (14 core + 13 inference), CI on Python 3.12, no dataset and no weights in Git. ## Browser-side ONNX export `model.onnx` is this checkpoint exported through the rfdetr ONNX pipeline: fp32, opset 17, 1,792 nodes over 41 distinct operators, SHA-256 `2de70b5781b7c6114712fda81f229af62f22b1329a9245e43b25b4ef0feae156`, and a **static input of [1, 3, 704, 704]**. The 704 does not contradict the `input 640` in `training_config.json`: training ran at 640, while the released inference paths (`inference/infer/infer.py`, `demo/app.py`) call `RFDETRLarge(pretrain_weights=…)` without a `resolution` override, so they run at the Large preset of 704 × 704, and `class_names.json`'s `input_resolution: 640` records the training value. Parity was measured, not assumed: five held-out val images yielding 21 boxes in total matched the PyTorch `predict()` baseline box-for-box — mean IoU 1.0, score delta 0, coordinate delta 0, every class equal. The browser demo reproduces those same five box counts (5/6/5/3/2) client-side. **fp16 was tried and rejected.** The 61,028,558 B half-precision export (0.50 × the fp32 file) still reproduced 21/21 boxes on the local ONNX Runtime CPU reference (mean IoU 0.9921–0.9976), but under WebGPU in a real browser the decoded boxes inflated to 33/24/18/26/8 against the 5/6/5/3/2 baseline and two of the five images also disagreed on class — the shortened mantissa pushed enough false positives above the 0.30 threshold that halving the download was not worth it. int8 was never attempted. Decoding follows `predict()` / `PostProcess._select_topk` (sigmoid over all query × class pairs → `topk(300)` → **strictly greater than** the threshold), not the per-query argmax shortcut found in the upstream export example. ## Dataset and attribution DsPCBSD+ is a public benchmark: Shengping Lv et al., 2024, Figshare DOI [`10.6084/m9.figshare.24970329.v1`](https://figshare.com/articles/dataset/DsPCBSD_/24970329), companion paper *Scientific Data* 11:811, DOI `10.1038/s41597-024-03656-8`. **Licence: CC BY 4.0 — attribution required.** Images are not redistributed here; obtain the dataset from the source above before reproducing any number. Published baseline comparison on the same val split (different input resolution and recipe, so directional only): Co-DETR 0.492, YOLOv6-L6 0.514 mAP@0.5:0.95. ## 繁體中文摘要 **RF-DETR-L 微調 · 9 類 PCB 表面瑕疵偵測(僅發布權重)** 以 Roboflow 的 [RF-DETR-Large](https://huggingface.co/Roboflow/rf-detr-large)(Robinson et al., arXiv:2511.09554,ICLR 2026 接收;訓練與評估所用版本 **1.8.3 屬作者紀錄**——倉內唯一機讀的版本依據是**推論端** `inference/infer/requirements.txt` 的釘死版本 `rfdetr==1.8.3`,訓練端 `requirements.txt` 只設 `>=1.8.0` 下限。隨權重封裝的 `training_config.json` 能辨識 run(`output_dir` 指向 `rfdetr_l_640_v11a_lrl`、`resume` 自 v9 最佳 EMA checkpoint),但**沒有任何套件版本欄位**,因此可重現性主張的依據是推論端鎖版加上作者側紀錄,而非訓練端依賴清單)為起點,在 **DsPCBSD+** 公開基準上做 640 解析度、三階段接力微調(v8 → v9 → v11a,共 10 個有效 epoch;本卡釋出的是最後一階段 v11a,lr 5e-5、11 epochs、每 epoch 748 steps)。 - 頭號數字 **mAP@0.5:0.95 = 0.5397**:這是拿 `checkpoint_best_ema.pth` 做**獨立端到端 pycocotools 重評**、3 個 seed(0/1/2)加 `cudnn.deterministic` 的平均值;mAP@0.5 = 0.8677、mAP@0.75 = 0.5710(與倉內 `class_names.json` 一致,舊版本節誤植 0.5715,已修)。 - **0.5411 是訓練日誌在 v11a epoch 9 記錄的 EMA 峰值**,不是重評值,兩者為不同測量,本卡以 0.5397 為準。 - 三個 seed 的 std = 0.0 來自評估端固定 seed 的確定性,**不代表模型穩定性**;逐筆 `eval_results.json` 未保留,因此 0.5397 屬彙總層級驗證。 - 類別表現:HB 0.8321 最高、SP 0.4025 最低。226×226 原圖中位數框寬約 21 px(此框尺寸統計屬作者紀錄,逐筆標註陣列未隨倉發布),屬小目標偵測,這是 mAP 天花板偏低的結構性原因;倉內可查的支持證據是 `class_names.json` 的 AP_small 0.4563 對比 AP_large 0.7386。 - 誠實記錄最後一階段(v9→v11a)增益只有 **+0.0008**;真正有效的變動是換架構+解析度、以及修正 COCO `file_name` 需為 `images/` 的 bug。倉內 `docs/notes/02-archived-directions.md` 記錄 **13 項初步測試**(其中 11 項列表於 `docs/results.md` 4.3,另兩項是中途停止的 RF-DETR 早期探測),因 run 目錄不在封裝內**列為未驗證**;多數未跑至收斂,不得寫成「已證明無效」。 - 本倉另有 `model.onnx`(fp32、opset 17、靜態輸入 **[1,3,704,704]**、121,612,490 bytes)供**瀏覽器端**推論:五張 held-out val 影像共 21 框,與 PyTorch `predict()` 基準**逐框一致**(平均 IoU 1.0、分數差 0、座標差 0、類別全等)。704 與設定檔的 `input 640` 不衝突——訓練在 640,而釋出推論路徑不覆寫 `resolution`,走 RF-DETR-L 預設的 704 × 704;`class_names.json` 的 `input_resolution: 640` 記錄的是訓練值。 - **fp16(61,028,558 B、0.50 倍)已試且否決**:本機 ORT CPU 基準仍 21/21 框(平均 IoU 0.9921~0.9976),但瀏覽器 WebGPU 下框數膨脹為 33/24/18/26/8(基準 5/6/5/3/2),且五張中有兩張類別也不一致,故線上版採 fp32;int8 未嘗試。 - 線上互動 Demo(推論跑在訪客瀏覽器、影像不上傳):。 - 授權:RF-DETR 為 Apache-2.0;DsPCBSD+ 為 **CC BY 4.0(必須署名)**。本倉不重新散布影像資料。 - 完整推論程式、測試與 CI 在 [NextBai/boardeye](https://github.com/NextBai/boardeye)。 **聲明**:本模型為工業光學檢測研究產出,非經證實的產線 AOI 方案,不得作為品質判定依據。專案為團隊協作成果(模型訓練與評估、工具鏈為主要貢獻範圍)。