The problem
Garment manufacturers still inspect fabric the slow way: a worker watches the roll unspool under bright light and marks defects by eye. It is tiring, inconsistent, and the defects that slip through — a hole here, a slub there — become rejected garments or customer complaints downstream. Manual inspection typically catches only the obvious flaws, and the checker cannot keep a quantitative log of defect rates per roll. This project replaces the eyeball with a camera and a convolutional neural network: a ResNet-50 model, pre-trained on ImageNet and fine-tuned on the published TILDA textile dataset, classifies each fabric frame into defect-free or one of seven defect types, while a Grad-CAM heatmap is thresholded into bounding boxes that show exactly where each defect sits. A web-based inspection console ties it together — upload a fabric photo, run the pipeline, and get labeled boxes with confidence scores plus a defect-rate dashboard across rolls. Nothing is overstated: accuracy figures are presented as design targets, and the delivered report documents the measured metrics from the actual training run.
How it works
- You photograph a fabric roll frame (or upload a swatch image); the console resizes it to 512×512 and normalizes it exactly as the training data was prepared.
- The ResNet-50 backbone extracts texture features; a global-average-pooling plus dense head outputs probabilities over the 8 classes (defect-free + 7 defect types).
- For any predicted defect class, a Grad-CAM heatmap is computed from the final convolutional layer to show which image regions drove the decision.
- The heatmap is thresholded and connected-component labeled into bounding boxes; boxes below the 0.50 confidence threshold are discarded.
- Each surviving box is drawn on the frame with its defect-type label and confidence score, and the frame gets a PASS or DEFECTIVE verdict.
- Frame results are aggregated per roll into a defect-rate log (defects per 100 m); rolls crossing the configurable rework threshold are flagged.
- The dashboard renders the trend across rolls, and the training notebook regenerates all metrics — per-class precision/recall and the confusion matrix — from the order's own training run.
Tech stack:
- Python 3 · PyTorch
- ResNet-50 · transfer learning
- TILDA textile dataset
- OpenCV · Albumentations
- Focal loss · class weights
- Flask inspection app
- HTML5 · CSS · JavaScript console
- ONNX model export
Dataset & model details
- Dataset: TILDA Textile Texture Database (DFG Texture Analysis group, University of Freiburg) — approximately 3,200 fabric images (768×512) spanning 8 fabric types in 4 structural classes (C1–C4), with a defect-free class (e0) and defect classes including hole, thread error, oil spot and foreign body. Slub, misweave, snag and broken-end examples are added from a supplementary mill collection labeled under the same 7-defect taxonomy.
- Task: 8-class fabric-frame classification with localization; input = 512×512×3 RGB image, output = probability distribution over 8 classes plus Grad-CAM-derived bounding boxes.
- Model: ResNet-50 backbone (~25.6 M parameters, ImageNet-pretrained, fine-tuned) → global average pooling → Dense(256, ReLU) → Dropout(0.4) → Dense(8, softmax); trained with focal loss and class weights.
- Metrics: Macro defect recall target ~92%+ and false-alarm rate target <5% on defect-free fabric (design targets for the built-to-order training run), per-class precision/recall/F1, confusion matrix. No metric is claimed as measured until the training run is executed for the order.
| Parameter | Value |
|---|---|
| Input format | 512 × 512 RGB fabric frame, normalized (design) |
| Classes | 8 (defect-free + 7 defect types) |
| Model parameters | Approximately 25.6 M (ResNet-50 backbone) |
| Defect recall | Target ~92%+ macro average (design target, not a measured claim) |
| False-alarm rate | Target <5% on defect-free fabric (design target) |
| Inference | Approximately 120–180 ms per frame on CPU (expected); real-time on GPU |
| Model file | Approximately 98 MB SavedModel / ONNX (approximate) |
| Demo | Single-file web console; demo detections are simulated, the delivered model is trained per order |
Project features
- [ResNet-50 defect classifier] ImageNet-pretrained ResNet-50 fine-tuned to an 8-way softmax — defect-free plus hole, slub, misweave, broken end, oil spot, snag and thread error — with the fine-tuning schedule documented.
- [Grad-CAM defect localization] Class-activation heatmaps are thresholded into bounding boxes over the fabric frame, each labeled with defect type and confidence, so the output shows where a defect is, not just that one exists.
- [Inspection web console] Upload any fabric photo, run the full pipeline in the browser demo, and get bounding-box overlays, a ranked detection list with confidence bars, and per-frame statistics (defect count, defective area, inference time).
- [Roll batch queue] Review multiple fabric rolls in one grid; each roll carries its frame count and a PASS/DEFECTIVE verdict with defect counts for quick triage.
- [Defect-rate dashboard] Tracks defects per 100 m of fabric across rolls with a configurable rework threshold, so quality trends are visible instead of anecdotal.
- [Imbalance-aware training] Focal loss with class weights counters TILDA's heavy defect-free skew; the train/val/test split is stratified by fabric roll so no roll leaks across splits.
- [Full training notebook] Data preparation, augmentation, model definition, training loop and evaluation in one reproducible notebook, including per-class precision/recall, the confusion matrix and training curves.
What is included
- Complete training & evaluation notebook (data prep, augmentation, training, metrics)
- Trained ResNet-50 defect classifier (SavedModel + ONNX export) with preprocessing code
- Fabric inspection web console wired to the trained model
- Per-class precision/recall, confusion matrix and training-curve plots
- Project report PDF (background, CNN/transfer-learning theory, methodology, measured results)
- PPT presentation for final review
- Viva Q&A preparation document (CNNs, transfer learning, Grad-CAM, focal loss, overfitting, dataset bias)
Limitations & prerequisites
- TILDA covers mostly patternless woven fabrics — bold printed or highly patterned textiles are a known hard case and may need extra training data.
- Detection quality depends on capture conditions: even diffuse lighting and a fixed camera distance are assumed; harsh shadows or motion blur degrade results.
- Subtle defects (snags, faint oil spots on dark fabric) are the weakest classes; the report calls out their lower recall honestly instead of hiding it.
- The ~92% recall and <5% false-alarm figures are design targets stated up front — the report documents the actually measured values after the order's training run.
- CPU inference at ~120–180 ms/frame suits roll-sample inspection, not full-speed continuous line scanning without a GPU.
- This is an educational prototype, not certified quality-control equipment — mill deployment would need calibration against the buyer's own rolls.
Frequently Asked Questions
Which dataset is used and why?
The TILDA Textile Texture Database from the DFG Texture Analysis group (University of Freiburg) — about 3,200 fabric images across 8 fabric types with a defect-free class and defect classes like hole, thread error and oil spot. It is the most-cited public benchmark for this exact task, so results are comparable with published literature.
How are defects localized if the model is a classifier?
Grad-CAM back-projects the predicted defect class onto the last convolutional layer, producing a heatmap of the regions that drove the decision; thresholding that heatmap yields the bounding boxes you see in the demo.
How is this different from weld or PCB defect-detection projects?
The domain is textile: the model learns weave textures rather than metal or circuit patterns, the defect taxonomy (slub, misweave, broken end, snag) is weaving-specific, and the dataset and augmentation are chosen for fabric, not X-ray or board imagery.
Can it inspect patterned or printed fabric?
Not reliably as shipped — TILDA is mostly patternless, and prints confuse texture-based detection. Extending to printed textiles needs additional training data, listed as future scope in the report.
What does the web demo show versus the delivered system?
The demo console runs the full interaction flow — upload, pipeline animation, boxes, dashboard — with simulated detections so it works instantly in a browser. The delivered system wires the same console to the genuinely trained model from the order's training run.
Is this project suitable for a final-year project?
Yes — for AI & Machine Learning, Computer Science and Textile programs. It demonstrates transfer learning, handling of imbalanced data, model interpretability with Grad-CAM, and a working inspection application. Suitable for B.E./B.Tech final-year projects in AI & Machine Learning, Computer Science and Textile Engineering.
Components & software requirements
- Python 3 · PyTorch
- ResNet-50 · transfer learning
- TILDA textile dataset
- OpenCV · Albumentations
- Focal loss · class weights
- Flask inspection app
- HTML5 · CSS · JavaScript console
- ONNX model export
Dataset & model details
- Dataset: TILDA Textile Texture Database (DFG Texture Analysis group, University of Freiburg) — approximately 3,200 fabric images (768×512) spanning 8 fabric types in 4 structural classes (C1–C4), with a defect-free class (e0) and defect classes including hole, thread error, oil spot and foreign body. Slub, misweave, snag and broken-end examples are added from a supplementary mill collection labeled under the same 7-defect taxonomy.
- Task: 8-class fabric-frame classification with localization; input = 512×512×3 RGB image, output = probability distribution over 8 classes plus Grad-CAM-derived bounding boxes.
- Model: ResNet-50 backbone (~25.6 M parameters, ImageNet-pretrained, fine-tuned) → global average pooling → Dense(256, ReLU) → Dropout(0.4) → Dense(8, softmax); trained with focal loss and class weights.
- Metrics: Macro defect recall target ~92%+ and false-alarm rate target <5% on defect-free fabric (design targets for the built-to-order training run), per-class precision/recall/F1, confusion matrix. No metric is claimed as measured until the training run is executed for the order.
Delivery information
Built-to-order project. Delivery timeline is shared after order confirmation based on current queue.
Support terms
Complete documentation, setup guide, and viva preparation included. Support for setup and explanation provided.