Low Cost Two-Stage Fabric Defect Detection at the Edge
Organizations: Department of Computer Science and Engineering, University of Dhaka, Dhaka, Bangladesh
Abstract
Fabric inspection in the garment industries of low-income economies remains largely manual, and commercial vision systems are priced beyond most small and medium mills. Because defects are sparse under controlled production, a natural response is a cascade: screen every frame with a cheap anomaly detector and invoke a full detector only on suspicious frames. We build such a cascade for four knit-fabric defect classes and deploy it end-to-end on an NVIDIA Jetson Nano with TensorRT FP16. Stage 1 is a compact convolutional autoencoder with decoder attention gates, an edge-weighted reconstruction loss, and feature-level distillation from a frozen YOLOv5n teacher; Stage 2 is YOLOv5n, invoked only on flagged frames. On a 249-image benchmark disjoint from detector training (20 defective, 229 non-defective), Stage 1 at a recall-prioritised threshold flags all 20 defective images (95% CI 0.83-1.00) at a false-positive rate of 49.3% (113/229), reducing false positives by 19.3% relative to a plain autoencoder (p=0.011). The parallel pipeline reaches 13.45 FPS against 9.86 FPS for a sequential YOLO-only loop. Our central finding comes from decomposing that 1.36x: 91% of it is attributable to overlapping JPEG decode with inference rather than to the cascade, which contributes only a 5.1% inference reduction at the measured forwarding rate p = 0.534. We further show that forwarding here is false-positive-limited rather than prevalence-limited - 85% of forwarded frames are false alarms - and quantify the 29-45% inference reduction attainable under tighter calibration. We report this as a caution for cascade speedups measured without controlling the data path, and position the system as AI-assisted triage rather than autonomous acceptance.
Figures & tables
| Source | Images | Notes |
|---|---|---|
| Fabric Detection [ 39 ] | 89 | Roboflow (DENEME) |
| ISL-Knit [ 38 ] | 2,587 | Bangladesh knit dyeing |
| Fabric [ 40 ] | 76 | Roboflow (Afrasiab) |
| defect-needle [ 41 ] | 32 | Roboflow (ecovers) |
| Fabric Defect Augmented [ 42 ] | 209 | Roboflow (TrainerWork) |
| Multifab (real) | 195 | Bangladesh garment factory |
| Class | Instances | Share |
|---|---|---|
| Fly yarn | 1,681 | 8.4% |
| Hole | 2,825 | 14.0% |
| Oil spot | 13,224 | 65.7% |
| Thread error | 2,399 | 11.9% |
| Total | 20,129 | 100% |
| Threshold | Recall (defects) | Overall accuracy |
|---|---|---|
| 0.0009 (low) | 80% (16/20) | 10.4% |
| 0.12 (high) | 35% (7/20) | 55.0% |
| Model | Recall | FP | FPR | Acc. |
|---|---|---|---|---|
| Base AE | 19/20 | 140/229 | 0.611 | 0.434 |
| [0.75, 1.00] | [0.54, 0.67] | |||
| Modified AE | 20/20 | 113/229 | 0.493 | 0.546 |
| [0.83, 1.00] | [0.43, 0.56] | |||
| Always-normal | 0/20 | 0/229 | 0.000 | 0.920 |
| Model | Par. | GFLOPs | mAP50 | mAP50-95 | Prec. | Rec. | Size |
|---|---|---|---|---|---|---|---|
| YOLOv5n | 1.76M | 4.1 | 0.742 | 0.363 | 0.825 | 0.637 | 3.7 MB |
| YOLOv5s | 7.02M | 15.8 | 0.716 | 0.345 | 0.775 | 0.653 | 14.3 MB |
| YOLOv8n | 3.01M | 8.1 | 0.676 | 0.339 | 0.759 | 0.604 | 6.2 MB |
| Model | TN | FP | FN | TP | Acc. | 95% CI |
|---|---|---|---|---|---|---|
| YOLOv5n | 28 | 2 | 1 | 171 | 199/202 = 98.5% | [0.957, 0.997] |
| YOLOv5s | 29 | 1 | 0 | 172 | 201/202 = 99.5% | [0.973, 1.000] |
| YOLOv8n | 30 | 0 | 20 | 152 | 182/202 = 90.1% | [0.851, 0.939] |
| Configuration | Inf. | Wall | Overhead | FPS |
|---|---|---|---|---|
| (ms) | (ms) | (ms) | ||
| YOLO-only (sequential) | 47.77 | 101.40 | 53.63 | 9.86 |
| AE-only (sequential) | 27.29 | 82.25 | 54.96 | 12.16 |
| Two-stage (parallel) | 45.36 | 74.33 | 28.97 | 13.45 |
| FPR | Inf. (ms) | vs. YOLO | ||
|---|---|---|---|---|
| Measured ( ) | 0.493 | 0.534 | 45.35 | |
| Projected | 0.200 | 0.264 | 33.89 | |
| Projected | 0.100 | 0.172 | 29.99 | |
| Projected | 0.050 | 0.126 | 28.03 | |
| Projected | 0.010 | 0.090 | 26.47 |