Deep Learning

Visual Inspection Code-Along

Perform a common visual inspection workflow and identify defects based on the image content.

To follow along:

  1. Download the code
  2. Open in MATLAB

Don’t have access? Get a free trial now.

Time to Complete:
15–30 minutes
Basic MATLAB skills

Need a refresher? Try a free, interactive tutorial.

Step 1

Load and Preprocess Data

Import your data and ensure it is ready for deep learning.


What you learned: To load and preprocess data

  • Load data using an image datastore
  • The imageDatastore function automatically labels the images based on folder names
  • You can augment your dataset by adding images of different scale and rotation
  • Image-based apps can significantly speed up common preprocessing tasks like cropping, labeling, and registering images

Step 2

Import Model

Learn a variety of options for deep learning models. 


What you learned: To import a deep learning model and modify it for transfer learning

  • Use a variety of pretrained models as a starting point for transfer learning
  • Use Deep Network Designer app to interactively alter the model for a new task
  • Import models and architectures from TensorFlow™-Keras, TensorFlow 2, Caffe, and the ONNX™ (Open Neural Network Exchange) model format

Step 3

Train the Model

Use the data and modified network to train a new image classifier.


What you learned: To modify a model for learning

  • Choose from a variety of training options, which change the training results
  • Models can take a long time to train depending on hardware and dataset size
  • Perform deep learning without needing to learn how to create a model from scratch

Step 4

Test the Model and Visualize Results​​​

Load the model and use the test data to see the accuracy of the model.


What you learned: To test the model on new data

  • Classify the test data (set aside in step 1) and calculate the classification accuracy
  • Visualize the test data with corresponding labels to ensure model accuracy on new data
  • Use Explainable AI techniques like GradCAM to visualize where in the image the model detected a defect.