negi3961's picture
Update README.md
bddc831 verified
|
Raw
History Blame Contribute Delete
5.3 kB
---
license: mit
language:
- en
tags:
- object-detection
- computer-vision
- yolov8
- defect-detection
- manufacturing
- industrial-inspection
- ultralytics
pipeline_tag: object-detection
base_model:
- Ultralytics/YOLOv8
---
# 🏭 Factory Defect Guard β€” YOLOv8 Industrial Defect Detection
Multi-domain industrial defect detection model trained on 29,000+ images across steel surfaces, PCBs, and industrial components. Detects **17 defect classes** in a single forward pass.
| Metric | Value |
|---|---|
| mAP@0.5 | **83.0%** (V6_MC) |
| mAP@0.5:0.95 | 56.4% |
| Precision | 78.8% |
| Recall | 72.2% |
| Model size | 22.5 MB |
| Input size | 640Γ—640 |
---
## πŸ” Defect Classes (17)
**Steel Surface (NEU Dataset)**
`crazing` Β· `inclusion` Β· `patches` Β· `pitted_surface` Β· `rolled_in_scale` Β· `scratches`
**PCB Defects**
`pcb_missing_hole` Β· `pcb_mouse_bite` Β· `pcb_open_circuit` Β· `pcb_short` Β· `pcb_spur` Β· `pcb_spurious_copper`
**Industrial Components (MVTec-derived)**
`metal_nut_defect` Β· `screw_defect` Β· `transistor_defect` Β· `tile_defect` Β· `cable_defect`
---
## πŸš€ Quick Start
```python
from huggingface_hub import hf_hub_download
from ultralytics import YOLO
# Load model
model_path = hf_hub_download(
repo_id = "negi3961/factory-defect-guard",
filename = "best_v6_mc.pt" # MC Dropout version β€” best accuracy
)
model = YOLO(model_path)
# Run inference
results = model.predict("your_image.jpg", conf=0.25)
results[0].show()
# Get detections
for box in results[0].boxes:
cls = int(box.cls)
conf = float(box.conf)
name = model.names[cls]
print(f"{name}: {conf:.2f}")
```
---
## πŸ“¦ Model Files
| File | Description | mAP@0.5 |
|---|---|---|
| `best_v6_mc.pt` | **Recommended** β€” V6 fine-tuned with MC Dropout | **0.830** |
| `best.pt` | V6 base model | 0.796 |
Use `best_v6_mc.pt` for production. `best.pt` is kept for reproducibility.
---
## πŸ—‚οΈ Training Details
### Datasets Used
| Dataset | Domain | Images |
|---|---|---|
| NEU Surface Defect Database | Steel surface | ~1,800 |
| PCB Defect (akhatova) | PCB original | ~1,600 |
| PCB Dataset (nakul8820) | PCB augmented | ~2,000 |
| PCB Defect (norbertelter) | PCB YOLO format | ~10,668 |
| MVTec AD subset | Industrial objects | ~428 |
| Magnetic Tile Defects | Tile surface | ~2,688 |
| Surface Defect (yidazhang07) | Mixed | ~4,194 |
| **Total** | | **~29,354** |
### Training Config (V6)
```yaml
model: YOLOv8s
epochs: 60
imgsz: 640
batch: 16
optimizer: AdamW
lr0: 0.0001
mosaic: 1.0
mixup: 0.2
patience: 20
platform: Kaggle GPU (Tesla T4)
```
### Training Progression
| Run | Epochs | mAP@0.5 | Notes |
|---|---|---|---|
| V5 | 43 | 0.7477 | Initial training |
| V6 | 60 | 0.7960 | Full run, AdamW |
| V6_MC | +fine-tune | **0.8300** | MC Dropout added |
---
## πŸ“Š Per-Class mAP@0.5
| Class | mAP@0.5 |
|---|---|
| `tile_defect` | 99.5% |
| `pcb_missing_hole` | 99.3% |
| `pcb_short` | 95.5% |
| `pcb_open_circuit` | 90.7% |
| `patches` | 91.6% |
| `pcb_spurious_copper` | 91.1% |
| `pcb_mouse_bite` | 81.8% |
| `metal_nut_defect` | 85.5% |
| `inclusion` | 81.3% |
| `scratches` | 80.7% |
| `cable_defect` | 82.3% |
| `rolled_in_scale` | 57.4% |
| `screw_defect` | 56.8% |
| `transistor_defect` | 54.0% |
| `crazing` | 48.9% |
> **Note:** `crazing` is the hardest class β€” subtle surface texture variation makes it difficult to detect. `tile_defect` achieves near-perfect accuracy due to strong visual contrast.
---
## πŸ› οΈ Custom Inference Pipeline
```python
from huggingface_hub import hf_hub_download
from ultralytics import YOLO
import cv2
CLASSES = [
'crazing', 'inclusion', 'patches', 'pitted_surface',
'rolled_in_scale', 'scratches', 'pcb_missing_hole',
'pcb_mouse_bite', 'pcb_open_circuit', 'pcb_short',
'pcb_spur', 'pcb_spurious_copper', 'metal_nut_defect',
'screw_defect', 'transistor_defect', 'tile_defect', 'cable_defect'
]
model_path = hf_hub_download("negi3961/factory-defect-guard", "best_v6_mc.pt")
model = YOLO(model_path)
def inspect(image_path, conf_threshold=0.25):
results = model.predict(image_path, conf=conf_threshold, verbose=False)
detections = []
for box in results[0].boxes:
detections.append({
"class": CLASSES[int(box.cls)],
"confidence": round(float(box.conf), 3),
"bbox": box.xyxy[0].tolist()
})
return detections
print(inspect("surface_sample.jpg"))
```
---
## πŸ“‹ Requirements
```
ultralytics>=8.0.0
huggingface_hub
torch>=2.0.0
Pillow
opencv-python
```
---
## ⚠️ Limitations
- Model trained on specific public benchmark datasets β€” real factory images may need fine-tuning
- `crazing` and `transistor_defect` classes have lower accuracy (~49–54%) and may produce false negatives on ambiguous textures
- Optimized for 640Γ—640 input; very small defects on high-resolution industrial cameras may need tiling
---
## πŸ”— Links
- **GitHub:** [github.com/chandanNegi39671/factory-defect-guard](https://github.com/chandanNegi39671/factory-defect-guard)
- **Training Notebook:** Kaggle (YOLOv8s, Tesla T4) (https://www.kaggle.com/code/negi1586/notebookce295c43f7)
---
## πŸ‘€ Author
**Negi** β€” ML Engineer
HuggingFace: [@negi3961](https://huggingface.co/negi3961)