Textile Defect Classifier
In this tutorial, you'll run the Textile Defect Classifier. By following this tutorial, you will learn:
- How to add a new custom/user application toEdge Insights for Industrial
- How to rebuildEdge Insights for Industrialwith this new application
- How to visualize the results of the custom application
Textile Defect Classifier is a reference implementation that can be executed as part of the
Edge Insights for Industrial
package. This reference implementation provides an AI-enabled approach to classify an input frame from a textile inspection camera as defective or good.
How the Textile Defect Classifier Works
The tutorial shows an example of how the
Intel® Distribution of OpenVINO™ toolkit
(OpenVINO™
) optimized classification networks can be leveraged in industrial quality inspection applications and deployed using
Edge Insights for Industrial
. This tutorial includes:
- Textile inspection video: Sample video that is used to simulate a textile inspection camera stream. The video includes 5 types of common textile defects, some of which are not easily noticeable to the human eye.
- Textile Defect Classifier UDF: Ingest the frames from the Video Ingestion pipeline and performs inference on each frame to classify it as defective or not. The rate at which each frame is classified is also recorded and displayed on the output Visualizer window of theEdge Insights for Industrialsoftware stack. The UDF utilizes the Inference Engine module from theIntel® Distribution of OpenVINO™ toolkitto optimize the inference on Intel hardware.
- Configuration files: VideoIngestion and VideoAnalytics configuration files to add the textile defect classifier UDF to theEdge Insights for Industrialpipeline.
- Intel hardware-optimized models: Deep learning classification models to detect textile defects optimized using theIntel® Distribution of OpenVINO™ toolkit; IR files generated by the Model Optimizer.
All communication between the image acquisition from sample video (VideoIngestion) and analytics to detect defects (VideoAnalytics) to visualizing the inspection results (Visualizer) occur over the Edge Insights Internal Message Bus, as shown in the following figure.

The sample textile data included as part of this application has 5 types of common textile defects, as shown in the following figure.

Get Started
The Textile Defect Classifier reference implementation is a plug-and-play application developed for the
Edge Insights for Industrial
package.
This application is a reference implementation of how to deploy an
OpenVINO™
optimized classification model using the
Edge Insights for Industrial
pipeline. Please be advised that the deep learning model included as part of this package is not intended to be a ready-to-deploy commercial textile defect classification model. We recommend that you retrain the model with a factory collected dataset before deploying it on the factory floor.
Prerequisites -
Edge Insights for Industrial Installation Options
Edge Insights for Industrial
Installation OptionsDownload and install the
Edge Insights for Industrial
package after selecting the Textile Defect Classifier Module in the custom download section of the video or video-timeseries use case. Both the use cases will download the video pipeline related services (VideoIngestion, VideoAnalytics, and Visualizer) required to satisfy the prerequisites for this application.
Step 1: Add Textile Defect Classifier UDF components
- Change working directory to the Textile Defect Classifier package and create an environment variable$EII_ HOMEto point to theIEdgeInsightsinstall path for ease of reference:cd $WORKDIR/edge_insights_industrial/Edge_Insights_for_Industrial_<version>/textile_defect_classifier/textile_defect_classifier/ EII_HOME=$WORKDIR/edge_insights_industrial/Edge_Insights_for_Industrial_<version>/IEdgeInsights$WORKDIRin this tutorial refers to the host system path where theEdge Insights for Industrialpackage was downloaded and unzipped.<version>indicates the downloaded version ofEdge Insights for Industrial.
- Copy the Textile Defect Classifier UDF file to theEdge Insights for IndustrialUDFs directory:cp -r textile/ $EII_HOME/common/video/udfs/python/.
- Modify the VideoIngestion (VI) and VideoAnalytics (VA) configuration files to add Textile Defect Classifier to the IEdgeInsights pipeline.
- Make a copy of the original VI & VAconfig.jsonfile:mv $EII_HOME/VideoIngestion/config.json $EII_HOME/VideoIngestion/config.json_original mv $EII_HOME/VideoAnalytics/config.json $EII_HOME/VideoAnalytics/config.json_original
- Copy the new VI and VAconfig.jsonto execute the textile classification application.Optionally, edit theva_config.jsonto use the inference hardware of choice [CPU/GPU/Myriad/HDDL]. Default is CPU.Note that the deep learning model used in the reference implementation is a deep model, and hence will take a few minutes for the initial loading into an accelerator (GPU/Myriad/HDDL) memory.cp vi_config.json $EII_HOME/VideoIngestion/config.json cp va_config.json $EII_HOME/VideoAnalytics/config.json
- Copy the textile inspection video sample to simulate camera stream input:cp textile.mp4 $EII_HOME/VideoIngestion/test_videos/.
- Add Tensorflow to VideoAnalyticsrequirements.txt. This Python module is being used for pre-processing the input image for the Textile Defect Classifier DL model.echo -e "\ntensorflow==1.15.0" >> $EII_HOME/VideoAnalytics/va_requirements.txtDifferent applications may have other requirements that can be added to the VideoAnalytics or VideoIngestionrequirements.txtfile.
- Follow theEdge Insights for Industrialinstructions to provision and launch the containers:# Configure the IEdgeInsights pipeline to use VideoIngestion, VideoAnalytics, Visualizer containers cd $EII_HOME/build/ python3 eis_builder.py -f video-streaming.yml # Provision cd $EII_HOME/build/provision sudo ./provision_eis.sh ../docker-compose.yml # Build cd $EII_HOME/build/ sudo sg docker -c 'docker-compose up --build -d' # Enable visualizer display xhost +
The result looks similar to:

Step 2: Check the Reference Implementation
Edge Insights for Industrial
builds the VideoIngestion, VideoAnalytics, Visualizer and WebVisualizer containers. The VideoIngestion container streams the sample textile video to the VideoAnalytics container that performs classification on each frame to detect occurrence of defects. Once the frame has been classified, the image is displayed on the Visualizer output window with the classification result and inference time.
Execute the following command to ensure all the containers are running without errors:
sudo docker ps
Check for Success
If it was successful, the results will be similar to:

Visualizer Output

The sample textile video has 5 types of defects that can be monitored using the visualizer output.
Step 3: Stop the Vision Pipeline
To stop
Edge Insights for Industrial
software, execute the following command:
cd $EII_HOME/build sudo sg docker -c 'docker-compose down'
ATTENTION
: To revert to the default PCB Demo application, move the VI and VA
config.json
files to the original copies [Step 1.3.a] and rebuild using the instructions in Step 1.5.
Troubleshooting
Troubleshooting a custom UDF application
The Textile Defect Classifier UDF file includes a tester code snippet that allows the file to be tested outside of the
Edge Insights for Industrial
environment on individual images to aid in debugging. Executing the application outside of the
Edge Insights for Industrial
deployment environment, requires
OpenVINO™
to be installed on the development system.
Please follow instructions on the
OpenVINO official page for installation steps for different inference hardware (CPU/GPU/Myriad).
To execute the application on the host development system, follow the instructions:
# Install Python dependencies pip3 install opencv-python==4.4.0.42 pip3 install tensorflow==1.15.0 # Set OpenVINO environment variables source /opt/intel/openvino_2021/bin/setupvars.sh -pyver 3.6
Run inference on a single test image, where
<version>
indicates the downloaded version of
Edge Insights for Industrial
:
cd $WORKDIR/edge_insights_industrial/Edge_Insights_for_Industrial_<version>/textile_defect_classifier/textile_defect_classifier/ # Run inference on single test image python3 textile/textile_classifier.py \ --model ./textile/ref/model.xml \ --label ./textile/ref/labels.txt \ --image ./sample_data/frame_a.png
Expected Output

Run inference on a directory of test images to calculate accuracy information of the model, where
<version>
indicates the downloaded version of
Edge Insights for Industrial
:
cd $WORKDIR/edge_insights_industrial/Edge_Insights_for_Industrial_<version>/textile_defect_classifier/textile_defect_classifier/ # Run inference on a directory of test images python3 textile/textile_classifier.py \ --model ./textile/ref/model.xml \ --label ./textile/ref/labels.txt \ --dir ./sample_data/
Expected Output

Summary and Next Steps
In this tutorial, you successfully ran the Textile Defect Classifier application and displayed the result using the
Edge Insights for Industrial
Visualizer output.
To get access to the deep learning training algorithm that was used to generate the Textile Defect classification model, please reach out to your Intel account manager.
As a next step, see the
Rotor Bearing Defect Detector Reference Implementation.