Hello everyone I am Muhtar. In this tutorial I am going to present image
classifier by using machine learning
neural networks for medical/satellite
images Part-2.
Note that Part-1 of this tutorial has
been presented previously. These are the
title and the link of the Part-1. In
order to understand this part you need
to see Part-1, first. Namely this is a
continuation of the Part-1.
However, here I would like to give a
brief recap about the Part-1. Let's see
this picture, steps in the image
classification by using machine learning.
Here, I have divided the whole process of
the building of the neural network into
several steps, see these steps,
steps from Step-1 to Step-8 have
been presented in the Part-1. Today, I
will present the remaining steps, especially,  Step-9 and Step-10. In Step-9,
I restore the saved trained neural
network. Then in Step-10, I validate the
neural network by using practical data.
In other words, this is a prediction
process by using the trained neural
network. Actually, in the end of the Part-1
I have executed the code, this was the execution results. Let's see it.
These are the epochs and corresponding
accuracies a that point of the training
epochs. Epoch, corresponding
accuracy;  this is epoch and this is
corresponding accuracy;  this is the final
training accuracy. The training seems to
be fairly good and reached an accuracy
rate of more than 93%.
However,  this accuracy is not satisfactorily good. Why? There are some reasons.
First, I have taken less training samples
for each output category.
Second,  since this is a tutorial I used only
a single image for the training sample
collections. In practice multiple images
should be used for the collection of the
training samples.
Thus, representative samples can be
collected so that classification
accuracy should be increased as well.
Third, I have set the training-epochs
very low for speedy training. It was 300 loops. In practice this should be
set properly. You should choose higher
values, however, you may not choose a very
high value. If so it might be introduced
the infamous "over fit" issue. In fact,
the selection of the training rate and
the number of training epochs are
difficult to be defined. These
parameters are defined based on trial
and errors. So the final classification
accuracy is definitely affected by the
samples and their qualities. However, in
this tutorial, I am putting strong
emphasis on the knowhow about the topic. In addition, this is the accuracy history
plot. It showed us the changes of the
accuracy during the training process. Now,
let's start to restore the saved trained
neural network. Okay, this is the saved path
of the saved trained neural network. I
copy it from here,
the last code execution, and paste it to
here. I will use it later in this Part-2.
import "numpy" as "np"; import "TensorFlow" as "tf";  from PIL import "Image"; import
"matplotlib.pyplot" as "plt"; from "matplotlib" import "colors"
Step-9,  restore the saved neural network;  "saved_path"
Okay, then, "res_sess  = tf.Session()".
"saver = tf.train.import_meta_graph (path + '.meta').
Now,  we can restore the "res_sess, 
saved_path". Okay, great! "Prediction =
tf.argmax(Y, 1)". Step-10,  validate the restored neural network.
Okay,  open an image (input data).
"im = np.array(Image.open('sport.jpeg')).
"size = im.shape". Now, define output
array for the classified image.
Okay, now loop through the whole image.
for y in range(size[0]).
for x in range(size[1]). Now,  we are going
to get the "x_vector = im[ y, x, 0:size[2]).
since we have three bands (RGB). "prediction_run =
res_sess.run(prediction, feed_dict = {X: [x_vec]}).
"output[y, x] = prediction_run[0]. Get the index of the maximum
value. This is the end of the
loop. Now,  we are going to create a color
map, since we have 7 output categories. So we need seven colors.  'grey', 'cyan',
'green', ' red', 'white', 'blue', and 'navy'.
Okay, now display the classified, 
display the original and
classified image/result.
the original image then display the
classified image/result. "imshow"
colormap. Then, set some titles.
"Cassified image". Okay, this is the end of the restore code.
Let's see. Runt it, what's happens! Okay, this is the classified result. However we don't have title of the
original image. We do not have title, so let's see we have some errors? Okay,
The session is restored. And it's running. Okay, this is
the final classification result. This is the classified image. Let's see
corresponding places in both images.  See here,
corresponding place.
93 percent. It's fairly good. So this is
the code to restore the saved trained
neural network.
This is the code. You can find this code
in the link in the YouTube video.
