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
Figure 1: Two-stage fabric defect detection (logical flow). Stage 1 filters normal frames; Stage 2 runs only on flagged anomalies. Deployment uses a pipelined producer–consumer layout (Section 4.4 ), not strict AE-then-YOLO serialisation on every frame.
Figure 2: System architecture with per-stage latency. Camera input is preprocessed and screened by Stage 1 (AE). Only anomalous frames are forwarded to Stage 2 (YOLO) for localisation and classification.
Figure 3: The four defect types with in-image labels.
Figure 4: Base autoencoder. Encoder compresses input x to latent y ; decoder reconstructs x~ ; training minimises L=∥x−x~∥2 .
Figure 5: Modified autoencoder: encoder, bottleneck, and decoder with attention gates.
Figure 6: Distillation framework. A frozen YOLOv5n teacher provides defect-aware features, projected to match the autoencoder’s latent space. The autoencoder aligns its latent representation with these features while minimising reconstruction error. At inference, only the autoencoder (left branch) runs.
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
Table 1: Dataset composition by source (4,188 images). Real and synthetic in-house images are listed separately; no synthetic image is used for evaluation.
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%
Table 2: Defect class distribution (instance counts; 20,129 total)
Threshold
Recall (defects)
Overall accuracy
0.0009 (low)
80% (16/20)
10.4%
0.12 (high)
35% (7/20)
55.0%
Table 3: Canny Stage 1 on the 249-image benchmark. Neither threshold is usable: the low setting flags nearly all normal frames, the high setting misses most defects.
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
Table 4: Base vs. modified autoencoder on the 249-image benchmark (20 defective, 229 non-defective) at τ=0.00245 . FPR = false-positive rate on the 229 non-defective images. Brackets are Clopper–Pearson 95% intervals. The final row gives the trivial classifier that labels every frame normal, included because the accuracy column is otherwise easy to misread.
Figure 7: Base vs. modified autoencoder: defects found (of 20), false positives, and normal images correctly passed (of 229). The false-positive reduction is the supported effect; the one-image recall difference is not.
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
Table 5: Stage-2 candidates at 320×320 . Box-level metrics on the validation split.
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]
Table 6: Image-level performance on the 202-image validation split (172 defective, 30 clean), with confusion-matrix counts and Clopper–Pearson 95% intervals on accuracy. YOLOv5n and YOLOv5s differ by two images; YOLOv8n is separated from both by its 20 false negatives.
Figure 8: YOLOv5n detection example ( 320×320 ): bounding boxes and confidence scores for the four defect classes.
Figure 9: Model size versus [email protected] for the Stage-2 candidates. YOLOv5n is selected for footprint; the mAP differences among the three are within the resolution of the validation split.
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
Table 7: Jetson Nano runtime on the 249-image benchmark (TensorRT FP16, τ=0.00245 , p=0.534 ). Inference for the two-stage row is tAE+ptYOLO=22.67+0.534(42.47) . The overhead column is wall minus inference and is the quantity that turns out to matter.
Figure 10: Wall time decomposed. The inference bars are nearly equal (47.77 vs. 45.36 ms): the cascade saves little detector compute at p=0.534 . Almost the entire difference in total height is non-inference time, which the parallel runtime overlaps and the sequential baseline does not.
FPR
p
Inf. (ms)
vs. YOLO
Measured ( τ=0.00245 )
0.493
0.534
45.35
−5.1%
Projected
0.200
0.264
33.89
−29.0%
Projected
0.100
0.172
29.99
−37.2%
Projected
0.050
0.126
28.03
−41.3%
Projected
0.010
0.090
26.47
−44.6%
Table 8: Projected forwarding rate and inference cost at π=0.0803 as a function of Stage-1 false-positive rate, from Eq. ( 6 ) with tAE=22.67 ms and tYOLO=42.47 ms. Only the first row is measured; the rest assume recall is preserved and are upper bounds on the achievable benefit.
Harokopio University of Athens, Athens, Greece · National and Kapodistrian University of Athens, Athens, Greece · Archimedes, Athena Research Center, Athens, Greece +1