File size: 3,625 Bytes
4321377 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | ---
license: mit
tags:
- image-classification
- random-forest
- pcb
- component-classification
- electronics
- explainable-ai
- scikit-learn
datasets:
- ParsaVictor/pcb-component-classifier
pipeline_tag: image-classification
library_name: scikit-learn
---
# PCB Component Classifier
A Random Forest over **33 hand-engineered computer-vision features** that classifies discrete electronic components — resistors, capacitors, diodes, inductors, transistors and ICs — from a single image, and can explain *why* it reached each decision.
No GPU, no pretrained backbone, ~50 ms per image on a laptop CPU.
Part of the [PCB Inspection Suite](https://huggingface.co/ParsaVictor/pcb-inspection-suite). Trained on [`ParsaVictor/pcb-component-classifier`](https://huggingface.co/datasets/ParsaVictor/pcb-component-classifier). Full pipeline, feature extraction code, and the explanation renderer: [GitHub: pcb-component-classifier](https://github.com/ParsaVictor/pcb-component-classifier).
## Results
Trained on 1,195 labelled images across 6 classes. Evaluated on a stratified 25% test split, and on a **120-image holdout set never used in training or tuning**.
| Evaluation | Accuracy |
|---|---|
| Test split (299 samples) | **92.98%** |
| Holdout set (120 images) | **93.33%** (112/120) |
### Per-class performance (test split)
| Class | Precision | Recall | F1 | Support |
|---|---|---|---|---|
| Resistors | 0.93 | 1.00 | 0.96 | 154 |
| Transistors | 1.00 | 0.90 | 0.95 | 21 |
| ICs | 0.97 | 0.88 | 0.92 | 32 |
| Capacitors | 0.90 | 0.92 | 0.91 | 59 |
| Inductors | 0.88 | 0.78 | 0.82 | 18 |
| Diodes | 1.00 | 0.60 | 0.75 | 15 |
| **Weighted avg** | **0.93** | **0.93** | **0.93** | **299** |
Diodes are the honest weak spot — perfect precision but 0.60 recall on only 15 test samples (visually close to small capacitors, under-represented class).
### Confidence as a review gate
| Threshold | Accepted | Accuracy on accepted | Flagged for review | Errors caught |
|---|---|---|---|---|
| none | 100% | 93.3% | 0 | 0 / 8 |
| 0.50 | 88% | 98.1% | 14 | 6 / 8 |
| **0.60** | **79%** | **98.9%** | **25** | **7 / 8** |
| 0.70 | 66% | 98.7% | 41 | 7 / 8 |
Accepting only predictions above 0.60 confidence leaves 98.9% accuracy on the 79% it handles automatically, and routes 7 of the 8 errors into the fifth it hands to a human.
## Usage
```python
import joblib
from huggingface_hub import hf_hub_download
weights = hf_hub_download("ParsaVictor/pcb-component-classifier", "tree_rf.joblib")
clf = joblib.load(weights)
# Requires the 33-feature extractor from the GitHub repo (src/pcb_classifier/features.py)
# pred = clf.predict([features])
```
See the [GitHub repo](https://github.com/ParsaVictor/pcb-component-classifier) for the full feature-extraction pipeline and the six-panel decision-path explanation renderer.
## Files
- `tree_rf.joblib` — trained on isolated component photos (this dataset, 93.3% holdout accuracy)
- `feature_importance.csv` — the 33 features ranked by importance
## Related
- Training dataset: [pcb-component-classifier](https://huggingface.co/datasets/ParsaVictor/pcb-component-classifier)
- Training/inference code: [GitHub: pcb-component-classifier](https://github.com/ParsaVictor/pcb-component-classifier)
- Sibling model (board-level detection): [pcb-component-detection-yolo26](https://huggingface.co/ParsaVictor/pcb-component-detection-yolo26) — also ships a variant of this classifier (`tree_rf_boards.joblib`) retrained on training-board crops
- Full suite overview: [pcb-inspection-suite](https://huggingface.co/ParsaVictor/pcb-inspection-suite)
## License
MIT.
|