I am trying to find the best match between images using transfer learning convolutional neural network. I have 10 different classes of images. So I created 10 folders and I put each class together inside a folder.
Folder-1 (360 images of type 1)
Folder-2 (360 images of type 2)
Folder-3 (360 images of type 3)
Folder-10 (360 images of type 10)
I used Alexnet and retrained the network for my image data set and obtained the net file from this training.
layers(23) = fullyConnectedLayer(10);
layers(25) = classificationLayer
allImages = imageDatastore('WholeData_A', 'IncludeSubfolders', true, 'LabelSource', 'foldernames');
[trainingImages, testImages] = splitEachLabel(allImages, 0.8, 'randomize');
opts = trainingOptions('sgdm', 'InitialLearnRate', 0.001, 'MaxEpochs', 2, 'MiniBatchSize', 64, 'Plots','training-progress');
myNet_Experiment_X_A1 = trainNetwork(allImages, layers, opts);
I also measured the accuracy of the training and obtained high accuracy = 1
predictedLabels = classify(myNet_Experiment_X_A1, testImages);
accuracy = mean(predictedLabels == testImages.Labels)
Now I picked up an image "image_1.tif" from the same data set to predict the similary order for this image using the following code
Testing_Image = imread("image_1.tif");
p = predict(myNet_Experiment_X_A1, Testing_Image);
[p3,i3] = maxk(p,3);
All_posibilities = myNet_Experiment_X_A1.Layers(end).ClassNames(i3)
For example, if I picked an image "image_1.tif" from Folder-2, then I will have 3 predictions for this image
Predict-1: Folder-2 (because this image belong to this folder)
The problem is: when I repeat STEP-1 and STEP-2 for this same data set and testing the same image "image_1.tif" I get different results for Prediction-2 and Prediction-3 (Prediction-1 is constant and no problem).
Results from the second training as follows:
Predict-1: Folder-2 (OK, same as the first training)
Predict-2: Folder-7 (was Folder-4 in the first training)
Predict-3: Folder-5 (was Folder-7 in the first training)
Any idea what is wrong with this code or method?