mcthebest/PCB_RTDETR
PCB Defect Detection — RT-DETRv4 X on DsPCBSD+
RT-DETRv4 X fine-tuned on the DsPCBSD+ dataset for 9-class copper-layer defect detection.
Live Demo
Try it in your browser without any setup:
[https://huggingface.co/spaces/mcthebest/PCB_RTDETR](https://huggingface.co/spaces/mcthebest/PCB_RTDETR)
Upload your own PCB image or pick from 29 built-in test images. The confidence threshold is adjustable in the sidebar.
Model
Architecture: RT-DETRv4 X
RT-DETRv4 builds on the RT-DETR lineage (v1, v2, v3) with ideas from D-FINE and DEIM. The main addition is a semantic distillation framework that uses a frozen DINOv3 teacher during training only, adding no cost at inference.
Training loss:
L_total = L_det + λ · L_DSIL_det includes VFL, L1, GIoU, FGL, DDF, and MAL losses from D-FINE and DEIM. DINOv3 is not loaded at inference.
Training Configuration
Mosaic and MixUp augmentation were disabled due to memory constraints. Multi-scale training (480-800 px, 11 levels) was kept.
Results on DsPCBSD+ Validation Set
Overall COCO Metrics
Per-Class AP @ IoU=0.50:0.95
Per-Class F1 @ Conf>=0.5, IoU>=0.5
Comparison with SOTA on DsPCBSD+
RT-DETRv4 X matches or exceeds all compared methods at only 10 epochs on a single T4. PCB-FS, for comparison, used 100+ epochs with more resources.
Dataset: DsPCBSD+
DsPCBSD+ is a 2024 open dataset for PCB copper-layer defect detection, captured by a professional AOI system (AGLE'OL AOI-100 V8, 16K camera, controlled LED lighting). Nine defect categories, annotated at instance level:
S. Lv et al., "A dataset for deep learning based detection of printed circuit board surface defect," Scientific Data, vol. 11, no. 1, p. 811, 2024. https://doi.org/10.1038/s41597-024-03656-8
Files
The training code, config, and Streamlit app are in the companion Space: https://huggingface.co/spaces/mcthebest/PCB_RTDETR
Running Locally
Clone the Space and install dependencies:
git clone https://huggingface.co/spaces/mcthebest/PCB_RTDETR
cd PCB_RTDETR
pip install -r requirements.txtDownload the checkpoint:
from huggingface_hub import hf_hub_download
ckpt_path = hf_hub_download(
repo_id="mcthebest/PCB_RTDETR",
repo_type="model",
filename="last.pth",
)Or place it manually at outputs/rtv4_hgnetv2_x_pcb/last.pth, then run:
streamlit run app.pyHow Inference Works
The image is resized to 640x640 and passed through RT-DETRv4 X. The decoder outputs 300 candidate queries which the postprocessor filters by confidence threshold (default 0.30). Detections are returned as (labels, boxes, scores) and drawn with labeled bounding boxes. DINOv3 is not loaded at inference.
Known Limitations
- Small defects (AP=0.439): sub-32px defects like SP (Spur) are the hardest class.
- Only 10 epochs were run vs. the recommended 72. The learning curve had not plateaued, so more training should meaningfully improve mAP@50:95.
- The dataset was collected under controlled AOI conditions. Images from different lighting or camera setups may need domain adaptation.
- AR@100=0.686, meaning roughly 31% of defects are missed. Not production-ready for zero-miss QC pipelines.
References
- RT-DETRv4 — Liao et al., 2025
- D-FINE — Peng et al., ICLR 2025
- DEIM — Huang et al., CVPR 2025
- DINOv3 — Siméoni et al., 2025
- RT-DETRv4 GitHub
- DsPCBSD+ dataset
