Fabric Defect Detection

Fabric Defect Detection

Fabric inspection is an essential step in every textile industry. Fabric detection is an important part of maintaining the fabric’s quality. The automatic fabric fault detection system is required to reduce the cost and waste of time. Quality inspection is a major aspect of the modern industrial manufacturing process. Due to a lack of consistency in quality inspection, defective fabric may be introduced to the market. This causes the industry’s name at stake, leading to heavy losses. With this concept moving forward, a new detection method, which has high detection accuracy and detection speed, is needed to replace the manual work currently used this problem can be resolved by using initial image processing techniques, and then a designed AI system can start working on finding the defect in the fabric. Our designed system is responsible for the quality of the fabric by capturing images from the rolling fabric with a camera.

What is Fabric Defect Detection?

Fabric defect detection is the technique of identifying and categorizing defects in textile materials like yarns, textiles, and garments. These defects can include missing threads, holes, stains, and gaps in the fabric or knitting. Detecting these defects is critical to keeping product quality and guaranteeing customer happiness.

Traditional Methods vs. Deep Learning

Traditionally, humans performed manual inspections to discover fabric defects. This method is difficult, not adaptable, and prone to errors. Deep learning systems, on the other hand, are capable of accurately identifying defects in fabric images through autonomous analysis.


The major objectives of this project are: 

  • Fabric inspection is done completely automatic, with no human involvement. 
  • By using the latest trend Al (Machine Learning), the system self-learns by detecting the new defects on the fabric.
  • The faulty fabric is automatically stamped by the robotic arm.


Explanation Of Block Diagram

As we can see from the block diagram, here we use the camera to capture the fabric, after capturing the image of the fabric the DIP(Digital Machine Learning) module does image processing through its algorithms & by this, the trained system performs Machine Learning(ML). After this the system decides whether the fabric is defective or non-defective if it’s defective then the robotic arm stamp at that particular area of the fabric, or if it is nondefective then the fabric passed through the roller and the process repeats


  • The system is 24/7 capable for operation.
  • The system works efficiently.
  • The system is fully automatic, no human involvement. 
  • AI based system with continuous self-learning.

Challenges in Fabric Defect Detection

Despite its benefits, fabric defect detection using deep learning poses some challenges: 

Data Quality: Deep learning algorithms require substantial, high-quality labeled data to train efficiently. This can be difficult to get, especially in unusual or complex abnormalities. 

Deep learning algorithms are complex and require specialized knowledge to create and deploy. 

Interpretability: Deep learning algorithms might need help grasping how they make judgments. 

Generalization: Deep learning algorithms may need help generalizing to new, previously unknown faults, particularly if they are underrepresented in training data.

Fabric defect detection using deep learning

To make a fabric defect detection system using deep learning, download a dataset from Kaggle.

				# Importing Libraries
import os
import cv2
import numpy as np
import tensorflow as tf
from sklearn.model_selection import train_test_split


This block imports necessary libraries for file operations, image processing, numerical operations, deep learning, and dataset splitting.

				# Function to load and preprocess images
def load_images(folder_path):
    images = []
    for filename in os.listdir(folder_path):
        img = cv2.imread(os.path.join(folder_path, filename))
        img = cv2.resize(img, (224, 224))  # Resize images if needed
        img = img / 255.0  # Normalize pixel values

    return np.array(images)


This block defines a function load_images that takes a folder path as input and returns a numpy array of preprocessed images. It reads each image using OpenCV (cv2), resizes it to 224×224 pixels, and normalizes pixel values to the range [0, 1].

				# Load images from folders
defect_images = load_images("Defect_images")
non_defect_images = load_images("nondefect")


This block loads images from two folders: “Defect_images” and “nondefect”. It uses the load_images function defined earlier to preprocess the images.

				labels = np.zeros((len(defect_images) + len(non_defect_images), 2))
labels[:len(defect_images), 0] = 1
labels[len(defect_images):, 1] = 1


This block creates labels for the images. It creates a numpy array of zeros with dimensions (len(defect_images) + len(non_defect_images), 2). It sets the first column to 1 for defect images and the second column to 1 for non-defect images.

				all_images = np.concatenate((defect_images, non_defect_images), axis=0)


This block concatenates the defect and non-defect images into a single numpy array called all_images.

				# Split data into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(all_images, labels, test_size=0.2, random_state=42)


This block splits the data into training and testing sets using the train_test_split function from sklearn.model_selection. It uses 80% of the data for training and 20% for testing.

				# Define and train a simple CNN model
model = tf.keras.Sequential([
    tf.keras.layers.Conv2D(32, (3, 3), activation='relu', input_shape=(224, 224, 3)),
    tf.keras.layers.MaxPooling2D((2, 2)),
    tf.keras.layers.Conv2D(64, (3, 3), activation='relu'),
    tf.keras.layers.MaxPooling2D((2, 2)),
    tf.keras.layers.Conv2D(128, (3, 3), activation='relu'),
    tf.keras.layers.MaxPooling2D((2, 2)),
    tf.keras.layers.Dense(128, activation='relu'),
    tf.keras.layers.Dense(2, activation='softmax')


This block defines a simple CNN model using the Sequential API in TensorFlow. It consists of three convolutional layers with max-pooling, followed by a flatten layer and two dense layers. The output layer uses the softmax activation function to output probabilities for the two classes.



This block compiles the model with the Adam optimizer and categorical cross-entropy loss function. It also specifies that accuracy should be used as a metric for evaluation.

				model.fit(X_train, y_train, epochs=10, validation_data=(X_test, y_test))


This block trains the model on the training data for 10 epochs, using the validation data for evaluation.

				# Evaluate the model
loss, accuracy = model.evaluate(X_test, y_test)
print(f"Test Loss: {loss}, Test Accuracy: {accuracy}")


This block evaluates the trained model on the test data and prints the test loss and accuracy.

				#input from camera

new_image = cv2.imread("test2.png")
new_image = cv2.resize(new_image, (224, 224))
new_image = new_image / 255.0
new_image = np.expand_dims(new_image, axis=0)

prediction = model.predict(new_image)
if prediction[0][0] > prediction[0][1]:
    print("Apply Stamp")

    print("No stamp ")


This block loads a new image (“test2.png”) from disk, preprocesses it, and passes it through the trained model to make a prediction. If the predicted probability of the first class (defect) is higher than the second class (non-defect), it prints “Apply Stamp”; otherwise, it prints “No stamp”.

Fabric defect identification using deep learning can transform the textile business. By automating fault identification, deep learning algorithms can improve product quality, lower costs, and increase customer happiness. However, specific issues such as data quality and interpretability remain to be addressed. Deep learning algorithms will improve their ability to detect fabric problems with more study and development.

Final Year Project Ideas image

Final Year Projects

Data Science Project Ideas

Data Science Projects

project ideas on blockchain

Blockchain Projects

Python Project Ideas

Python Projects

CyberSecurity Projects

Cyber Security Projects

Web Development Projects

Web dev Projects

IOT Project Ideas

IOT Projects

Web Development Project Ideas

C++ Projects

Scroll to Top