Industrial Surface Defect Detection Reference Implementation
Published: 04/14/2021
Last Updated: 05/19/2021
Overview
This reference implementation provides an AI-enabled approach to segment defects from the surface which captured by an inspection camera.
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 segmentation networks can be leveraged in industrial quality inspection applications.
- Inference Module: Ingest the frames extracted from the video stream and performs inference on each frame to segment defects.
- Surface Inspection Video: Sample video that is used to simulate a surface defect inspection camera stream. In this referene implementation, we adopt public dataset DAGM (class 1-6). Download it from kaggle.com and convert from image format to video.
Figure 1: Architecture Diagram
Get Started
Industrial Surface Defect Detection is a reference implementation for the application using OpenVINO™ inference engine.
NOTE: This application is a reference implementation, not a production-ready custom commercially deployable Industrial Surface Defect Detection tool.
Step 1: Install the Reference Implementation
Select Configure & Download to download the reference implementation and then follow the steps below to install it.
- Open a new terminal, go to the downloaded folder and unzip the downloaded RI package:
unzip industrial_surface_defect_detection.zip
- Go to industrial_surface_defect_detection/ directory:
cd industrial_surface_defect_detection
- Change permission of the executable edgesoftware file:
chmod 755 edgesoftware
- Run the command below to install the Reference Implementation:
./edgesoftware install
- 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.
Figure 2: Product Key - When the installation is complete, you see the message “Installation of package complete” and the installation status for each module.
Figure 3: Install Success
Step 2: Set up a Python* Virtual Environment (Optional, recommended)
Creating and using a Python virtual environment helps isolate Python dependencies between different projects. This ensures the Python packages installed for this application does not affect the system dependencies.
1. Install Python packet manager and install the virtual environment modules: virtualenv and virtualenvwrapper
sudo apt install python3-pip
sudo pip3 install virtualenv virtualenvwrapper
2. Update ~/.bashrc to include the following lines at the bottom:
# virtualenv and virtualenvwrapper
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
source /usr/local/bin/virtualenvwrapper.sh
3. Reload the changes to ~/.bashrc:
source ~/.bashrc
4. Create a Python 3.6 virtual env for the reference implementation:
mkvirtualenv -p python3.6 sdd
Check for Success
(sdd) before the terminal prompt indicates the virtual environment is active. Make sure the virtual environment is active before executing the application at any time.

To activate the virtual env on a new terminal window, use the command below:
workon sdd
5. Navigate to the package folder and install the required Python modules and make sure to activate the virtual env (refer to step above) every time the application is run to ensure the correct dependencies are utilized:
cd industrial_surface_defect_detection/Industrial_Surface_Defect_Detection_<version #>/Industrial_Surface_Defect_Detection/Surface_Defect_Detection/
pip install -r requirements.txt
Step 3: Download DAGM Dataset
Download DAGM dataset from kaggle.com.
Pre-trained model covered subset of DAGM (class 1-6), sample data as:

Step 4: Check the Reference Implementation
The reference implementation uses the Inference Engine module for performing inference on test images.
The output of six types of defects will look like the image below:

Execute the following command to run inference on a single test image:
# Set OpenVINO environment variables if not already done
source /opt/intel/openvino_2021/bin/setupvars.sh -pyver 3.6
python inference.py \
--model <path/to/OpenVINO/XML/file> \
--input <path/to/single/test/image> \
--device <target device for inference 'CPU, GPU, MYRIAD, HDDL' - CPU is default>
# Example command using default values :
python inference.py \
--model ./models/model.xml \
--input ./data/class1_0837.png
Check for Success
If it was successful, the results will be as follows:

The segmentation output is also saved in montages/ folder in the current directory.

Execute the following command to run inference on a directory of images:
# Set OpenVINO environment variables if not already done
source /opt/intel/openvino_2021/bin/setupvars.sh -pyver 3.6
python inference.py \
--model <path/to/OpenVINO/XML/file> \
--input <path/to/directory/of/images> \
--device <target device for inference 'CPU, GPU, MYRIAD, HDDL' - CPU is default>
# Example command using default values :
python inference.py \
--model ./models/model.xml \
--input ./data/
Check for Success
If it was successful, the results will be as follows:

The segmentation outputs for all images in the test directory will also be saved in montages/ folder in the current directory. The output for Class6_0160.PNG is shown in the screen below:

How to Uninstall Dependencies Installed by this Documentation
The Python modules installed from the requirements.txt file is limited to the virtualenv (sdd). To uninstall these dependencies completely, simple deactivate the vritualenv and remove it.
deactivate
rmvirtualenv sdd
Check for Success
If it was successful, the terminal output will be as follows:

To uninstall all packages installed by the edgesoftware script, use the command below:
cd industrial_surface_detect_detection
./edgesoftware uninstall -a
Check for Success
If package uninstall was successful, the terminal output will be as follows:

Summary and Next Steps
You successfully ran the Industrial Surface Defect Detection application and displayed the result using the openVINO™ Inference Engine.
To get access to the deep learning training algorithm that was used to generate the Industrial Surface Defect Detection model, please contact 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 Industrial Surface Defect Detection 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
ModuleNotFoundError: 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
ModuleNotFoundError: No module named ‘cv2’

Activate the virtual environment by executing the below command and run the application again.
workon sdd
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.