GitHub Repository Description: An automated, end-to-end deep learning pipeline for detecting textile defects using the ZJU-Leaper dataset. Includes highly optimized Kaggle notebooks for training and exporting YOLOv7, YOLOv11, and YOLOv26 models.
Below are the inference results obtained from our optimized models on the validation set. Defective areas are highlighted with red bounding boxes along with their confidence scores.
Note: YOLOv7 training inference visual results are currently pending and will be added soon.
This project provides a comprehensive and scalable solution for Textile Defect Detection, heavily optimized for the ZJU-Leaper dataset in a Kaggle environment. To ensure high accuracy and overcome raw data class imbalances, the pipeline automatically processes, balances, and augments the data before feeding it into state-of-the-art YOLO architectures.
Three separate Jupyter Notebooks (.ipynb) are provided to demonstrate the pipeline across different YOLO generations:
- YOLOv7 (
YOLOv7_Textile_Defect_Detection.ipynb) - YOLOv11 (
YOLOv11_Textile_Defect_Detection.ipynb- powered by Ultralytics) - YOLOv26 (
YOLOv26_Textile_Defect_Detection.ipynb- powered by Ultralytics)
The original ZJU-Leaper dataset contains approximately 75,000 textile images, but defective samples are significantly outnumbered by normal (defect-free) samples. Our preprocessing pipeline automatically solves this by:
- Balancing the classes: Randomly sampling up to
5,000defective images and5,000normal images to construct a stable ~10k image dataset. - XML to YOLO Conversion: Dynamically parses YOLO bounding box coordinates (
0-1normalized format) from the original XML annotations. - Train/Val Split: Uses a standard
80/20split for robust training and validation.
Each notebook has been carefully tuned to squeeze the maximum performance out of Kaggle's T4/P100 GPUs:
- Epochs (
20): Increased to allow the models sufficient time to learn from the expanded 10K image dataset. - Batch Size (
32): Optimized to properly utilize GPU VRAM while maintaining fast and stable gradient updates. - Label Smoothing (
0.1): Applied to prevent the models from becoming overconfident, thereby improving validation metrics. - Augmentation (YOLOv11 & YOLOv26):
mosaic=1.0(Enabled 100%)mixup=0.15(Enabled 15%)close_mosaic=5(Disabled during the final 5 epochs to allow the network to fine-tune on realistic feature details).
All three notebooks are structured into 6 clear stages that run autonomously on Kaggle:
- Environment Setup: Installs dependencies (
ultralyticsfor v11/v26, and custom legacy PyTorch 2.6 patches foryolov7). - Data Preprocessing: Executes the XML-to-YOLO conversion, generates subsets, and balances the defect classes.
- YAML Configuration: Creates the
data.yamlnecessary for training. - Optimized Training: Starts the training process using the respective YOLO architectures and optimized hyperparameter profiles.
- Inference & Visualization: Predicts bounding boxes on the validation set and visualizes the detected defects alongside confidence scores using
matplotlib. - ONNX Export: Generates an
.onnxversion of the best PyTorch weights (best.pt) for cross-platform, local real-time deployment.
- Open Kaggle and create a new Notebook.
- Add the ZJU-Leaper dataset to your Kaggle environment.
- Upload one of the
YOLOv<version>_Textile_Defect_Detection.ipynbfiles via the File -> Import Notebook option. - Set your Kaggle accelerator to GPU T4 x2 or P100.
- Click Run All. The model weights (
best.ptandbest.onnx) will be generated in your working directory.
If you prefer running the code locally, you will need:
pip install ultralytics opencv-python matplotlib tqdm pyyaml torch torchvision onnx onnxruntimeNote: Ensure your local environment has the dataset structured similarly to the Kaggle notebook paths (/images and /xmls).







