Instructions to use JcProg/PCBInspect-BodyDefect with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- ultralytics
How to use JcProg/PCBInspect-BodyDefect with ultralytics:
# Couldn't find a valid YOLO version tag. # Replace XX with the correct version. from ultralytics import YOLOvXX model = YOLOvXX.from_pretrained("JcProg/PCBInspect-BodyDefect") source = 'http://images.cocodataset.org/val2017/000000039769.jpg' model.predict(source=source, save=True) - Notebooks
- Google Colab
- Kaggle
Upload README.md with huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
tags:
|
| 4 |
+
- image-classification
|
| 5 |
+
- pcb
|
| 6 |
+
- aoi
|
| 7 |
+
- yolo26
|
| 8 |
+
- onnx
|
| 9 |
+
- computer-vision
|
| 10 |
+
- dataset:custom
|
| 11 |
+
library_name: ultralytics
|
| 12 |
+
pipeline_tag: image-classification
|
| 13 |
+
---
|
| 14 |
+
|
| 15 |
+
# PCBInspect-BodyDefect
|
| 16 |
+
|
| 17 |
+
Part of the **SentinelPCB defect-inspection router**: a region classifier dispatches each
|
| 18 |
+
component ROI crop to a region-specific defect classifier. Sibling repos:
|
| 19 |
+
[PCBInspect-Region](https://huggingface.co/JcProg/PCBInspect-Region), [PCBInspect-BodyDefect](https://huggingface.co/JcProg/PCBInspect-BodyDefect), [PCBInspect-LeadDefect](https://huggingface.co/JcProg/PCBInspect-LeadDefect), [PCBInspect-TextDefect](https://huggingface.co/JcProg/PCBInspect-TextDefect).
|
| 20 |
+
|
| 21 |
+
Companion structural-feature detector (unrelated task — detects MountingHole/ComponentBody/
|
| 22 |
+
SolderJoint/Lead, not defects): [PCBInspect-AI](https://huggingface.co/JcProg/PCBInspect-AI).
|
| 23 |
+
|
| 24 |
+
## Role
|
| 25 |
+
|
| 26 |
+
Defect classifier for crops routed as `Body` by the region classifier. The hardest of the three specialists — six classes with real class imbalance.
|
| 27 |
+
|
| 28 |
+
## Model
|
| 29 |
+
|
| 30 |
+
- Base: `yolo26s-cls` ([Ultralytics](https://docs.ultralytics.com/models/yolo26/)),
|
| 31 |
+
classification head, fine-tuned on AOI component-ROI crops.
|
| 32 |
+
- Export: ONNX, opset 17, no NMS (classification only) — single input
|
| 33 |
+
`images` `(1, 3, 640, 640)` RGB, normalized `/255`, NCHW; single output `output0`
|
| 34 |
+
`(1, 6)` raw logits (apply softmax yourself for probabilities).
|
| 35 |
+
- Classes (6), index order = `labels.json`: **ForeignMaterial, Golden, MissingPart, Shift, Tombstone, WrongPart**.
|
| 36 |
+
|
| 37 |
+
## Data
|
| 38 |
+
|
| 39 |
+
Trained on a proprietary AOI dataset of SMT component-ROI crops (paired defect-free reference +
|
| 40 |
+
defective capture per physical site), not publicly released. Split is grouped by physical
|
| 41 |
+
capture site (never by raw image) so a component's reference and defect crop never straddle
|
| 42 |
+
train/val/test.
|
| 43 |
+
|
| 44 |
+
## Metrics
|
| 45 |
+
|
| 46 |
+
**val** (top-1 0.948, macro-F1 0.875, n=784):
|
| 47 |
+
|
| 48 |
+
| class | precision | recall | f1 | support |
|
| 49 |
+
|---|---|---|---|---|
|
| 50 |
+
| ForeignMaterial | 0.996 | 0.975 | 0.985 | 276 |
|
| 51 |
+
| Golden | 1.000 | 1.000 | 1.000 | 200 |
|
| 52 |
+
| MissingPart | 0.706 | 0.706 | 0.706 | 17 |
|
| 53 |
+
| Shift | 0.929 | 0.897 | 0.913 | 146 |
|
| 54 |
+
| Tombstone | 0.773 | 0.739 | 0.756 | 23 |
|
| 55 |
+
| WrongPart | 0.851 | 0.934 | 0.891 | 122 |
|
| 56 |
+
|
| 57 |
+
**test** (top-1 0.941, macro-F1 0.871, n=780):
|
| 58 |
+
|
| 59 |
+
| class | precision | recall | f1 | support |
|
| 60 |
+
|---|---|---|---|---|
|
| 61 |
+
| ForeignMaterial | 0.996 | 0.963 | 0.979 | 267 |
|
| 62 |
+
| Golden | 0.995 | 1.000 | 0.998 | 200 |
|
| 63 |
+
| MissingPart | 1.000 | 0.500 | 0.667 | 22 |
|
| 64 |
+
| Shift | 0.901 | 0.938 | 0.919 | 146 |
|
| 65 |
+
| Tombstone | 0.833 | 0.769 | 0.800 | 26 |
|
| 66 |
+
| WrongPart | 0.813 | 0.916 | 0.862 | 119 |
|
| 67 |
+
|
| 68 |
+
## Limitations
|
| 69 |
+
|
| 70 |
+
`MissingPart` and `Tombstone` are the weak classes (94 and 131 raw examples total, concentrated on 12 and 15 distinct part-numbers respectively). Test: MissingPart precision 1.00 / recall 0.50 (conservative — misses about half, never false-alarms); Tombstone F1 0.80. More examples across more board/package designs would improve both; see the companion data-exploration notebook.
|
| 71 |
+
|
| 72 |
+
## Usage
|
| 73 |
+
|
| 74 |
+
```python
|
| 75 |
+
import onnxruntime as ort
|
| 76 |
+
import numpy as np
|
| 77 |
+
from PIL import Image
|
| 78 |
+
|
| 79 |
+
sess = ort.InferenceSession("model.onnx", providers=["CPUExecutionProvider"])
|
| 80 |
+
img = Image.open("crop.jpg").convert("RGB").resize((640, 640))
|
| 81 |
+
x = (np.asarray(img, dtype=np.float32) / 255.0).transpose(2, 0, 1)[None, ...]
|
| 82 |
+
(logits,) = sess.run(None, {"images": x})
|
| 83 |
+
probs = np.exp(logits) / np.exp(logits).sum()
|
| 84 |
+
print(probs)
|
| 85 |
+
```
|