Textile Defect Classifier Reference Implementation
Published: 12/29/2020
Last Updated: 04/07/2021
Overview
This reference implementation provides an AI-enabled approach to classify an input frame from a textile inspection camera as defective or good.
Select Configure & Download to download the reference implementation and the software listed below.
- Time to Complete: Approximately 30 minutes
- Programming Language: Python* 3.6
- Available Software: Intel® Distribution of OpenVINO™ toolkit 2021.2
Target System Requirements
- Ubuntu* 18.04 LTS
- Intel® Core™ i5 processor or above with 16GB of RAM
How It Works
The application uses the inference engine included in the Intel® Distribution of OpenVINO™ toolkit. The reference implementation shows an example of how classification networks can be leveraged in industrial quality inspection applications.
- Textile inspection video: Sample video that is used to simulate a textile inspection camera stream. The video includes five types of common textile defects, some of which are not easily noticeable to the human eye.
- Inference Module: Ingest the frames extracted from the video and performs inference to classify the frames as defective or not. The rate at which each frame is classified is also recorded and displayed on the terminal output.

Get Started
The Textile Defect Classifier is a reference implementation for the application using Intel® Distribution of OpenVINO™ toolkit inference engine.
NOTE: This application is a reference implementation, not a production-ready custom commercially deployable textile defect detection tool.
Install the Reference Implementation
Select Configure & Download to download the reference implementation and then follow the steps below to install it.
1. Open a new terminal, go to downloaded folder and unzip the RI package.
unzip textile_defect_classifier.zip
2. Go to textile_defect_classifier/ directory.
cd textile_defect_classifier/
3. Change permission of the executable edgesoftware file.
chmod 755 edgesoftware
4. Run the command below to install the Reference Implementation.
./edgesoftware install
5. During the installation, you will be prompted for the Product Key. The Product Key is contained in the email you received from Intel confirming your download.

6. When the installation is complete, you will see the message “Installation of package complete” and the installation status for each module.

Run the Application
Step 1: Activate the Python Virtual Environment
This application uses a Python virtual environment to isolate python dependencies between host system and the application. This ensures the Python packages installed for this application do not affect the system dependencies.
Activate the Virtual Environment for the Application
source setvirtualenv.sh
Check for Success
(m_classf) before the terminal prompt indicates the virtual environment is active. Please ensure the virtual environment is active before executing the application at any time.

Step 2: Execute the Reference Implementation
The Textile Defect Classifier OpenVINO™ reference implementation uses the Inference Engine module for performing inference on test images.
The sample textile data included as part of this package has five types of defects, as shown in Figure 5.

Run Inference on a Single Test Image
Set OpenVINO™ and Python virtual environment if not already done:
source setvirtualenv.sh
Run inference on a single textile image:
python textile/inference.py \
--model ./models/model.xml \
--label ./models/label.txt \
--image ./data/test_data/color_flecks/frame_a.png \
--device CPU
NOTE: Execute the command with -h flag to list all available options.
Check for Success
If it was successful, the results will be as follows:


Run Inference on a Directory of Images
Set OpenVINO™ and Python virtual environment if not already done:
source setvirtualenv.sh
Run inference on a directory of images:
python textile/inference.py \
--model ./models/model.xml \
--label ./models/label.txt \
--dir ./data/test_data/hole \
--device CPU
Check for Success
If it was successful, the results will be as follows:

Calculate the Confusion Matrix on a Test Dataset of Images
Set OpenVINO™ and Python virtual environment if not already done:
source setvirtualenv.sh
Run Inference on a test dataset of images:
python textile/inference.py \
--model ./models/model.xml \
--label ./models/label.txt \
--test_dataset ./data/test_data/ \
--confusion_matrix \
--device CPU
Check for Success
If it was successful, the terminal output will be as follows:


Optional Step 3: Test on More Data from Textile Video File
The sample data is extracted from the video ./data/textile.mp4. If you are interested in continuing testing with more images, please extract the frames from the video using below code snippet. This would save the video frames in ./data/vidframes/. Follow instructions above for validating on directory of images or single image.
import cv2
import os
os.mkdir('./data/vidframes/')
cap = cv2.VideoCapture('data/textile.mp4')
success,image = cap.read()
count = 0
while success:
cv2.imwrite("./data/vidframes/frame%d.png" % count, image)
success,image = cap.read()
print('Read a new frame: ', success)
count += 1
Exit the Application Environment
The python modules installed for the textile defect classifier application are limited to the virtualenv (m_classf). To deactivate the application, simply deactivate the virtualenv.
deactivate
Check for Success
If it was successful, the terminal output will be as follows:

Uninstall the Reference Implementation Package
The Python modules installed for executing this reference implementation are limited to the virtualenv (m_classf). To uninstall the package entirely use the command below:
cd ~/textile_defect_classifier/
./edgesoftware uninstall -a
Check for Success
If the package uninstall was successful, the terminal output will be as follows:

Summary and Next Steps
You successfully ran the Textile Defect Classifier application and displayed the result using the Intel® Distribution of OpenVINO™ toolkit Inference Engine.
To get access to the deep learning training algorithm that was used to generate the Textile Defect Classification model or the commercial version of this software, please reach out to your Intel account manager.
This application can be deployed on the factory floor using the Edge Insights for Industrial software package. A sample implementation can be downloaded by selecting the Textile Defect Classifier Application under Video Ingestion & Analytics (Step 3 of 6) tab from the Customize & Download section on the bottom-right.
Learn More
To continue learning, see the following guides and software resources:
Troubleshooting
Running the Application Results in "No Module Named 'openvino' Error"
Source the OpenVINO™ environment variables and run the application again.
source /opt/intel/openvino_2021/bin/setupvars.sh -pyver 3.6

Running the Application Results in "No Module Named 'cv2' Error"
Activate the virtual environment by executing the below command and run the application again.
source setvirtualenv.sh

Support Forum
If you're unable to resolve your issues, contact the Support Forum.
Product and Performance Information
Performance varies by use, configuration and other factors. Learn more at www.Intel.com/PerformanceIndex.