Copyright 2020 The MathWorks, Inc.
This sample code has been developed in collaboration with Kanazawa Institute of Technology on image classification using Convolutional Neural Networks. Using an original visualization app built with App Designer, students can visualize the training process of a neural network for improving its accuracy with their own handwritten letters while learning and experiencing practical techniques.
[Instructor] Print the worksheet (template.pdf) and provide it to each student.
[Student] Write 0-9 digits on the printed worksheet as follows.
[Instructor] Scan the worksheet written by each student and save it as a jpg image (In this example, we'll name it 1.jpg)
Run the following code, then enter your name and hit "OK".
myimportnumber2_0
This code extracts each digit image from the worksheet and saves it in each folder as shown below.
The code below trains a model while visualizing the training process.
myhandwrittentrain_visualization2_0
(Left figure) shows each test image. Each green box shows that the prediction is correct. Each red box shows that the prediction is wrong.
(Right figure) learning curve
In order for students to understand the training process, the code will save each model and learning curve as ‘netresult.mat’ at its accuracy reaching to 25%, 50%, 75% and training completion.
\hfill \break
myClassifierApp2_0
By running the code above, app pops up.
This app loads the test images and the saved networks.
In this GUI, you can change model to 25%,50%,75% accuracy and training completion at "Model Selection".
By changing model, you will notice how prediction changes
The image and score of a test image highlighted in yellow box is shown on the right-hand side.
The yellow box can be moved by clicking the bottom arrow icons.
In the step2 to step4, each student tested with his or her own data. Let's use another data from another student and see what will happen.
Rename your dataset to mypic1
movefile mypic mypic1
Change code line 20 in myimportnumber2_0.m file to load another scanned worksheet. Then run the following code.
myimportnumber2_0
Load two sets of data from two students and create a folder called mypic2
myhandwrittentrain_for2sets2_0
The rest of the workflow is the same as step4.
myClassifierApp2_0
You can also change test image in at “Change test image” and model sets at "Change model set".
MathWorks Products
- MATLAB
- Deep Learning Toolbox
- Image Processing Toolbox
- Computer Vision Toolbox
We thank Dr. Shinichi Taniguchi, Prof. Akira Nakamura and Dr. Tomoshige Kudo for their valuable proposals and discussion that greatly improved this sample code. We would also like to show our gratitude to Kanazawa Institute of Technology for their agreement to publish this code.