Matlab: Convolutional Netzwerk für Würfel Nummer Erkennung
(English) This post describes a Matlab function which uses a 7 layer convolutional network for dice number identification (numbers 1-12). It calls for the earlier proposed image processing methode shown in this post.
Mode of operation:Two methodes were tested. The dice as shown in previous post is just a tiny part of the whole image. With image processing, the dice itself is excluded and saved in a new folder sorted by number. They are loaded in "digitData". The it is splitted in trainigs set (4/5) and test set (1/5 of alle images). All in all I have 996 images and I tested the not processed images and the binare tresholded images, which suprisingly showed a higher accuracy for the non processed images. An all in all accuracy of 99.6% in the training set and 99.2% in the test set was achieved around 5% higher than for the binare images. In this image the value of accuracy is seen what the convolutional net predicts. A good improvement is seen in non processed images compared to binare ones.
The non processed images net had 4 fault predictions and the other one 15.
The matlab function "trainNetwork" was used for the training process which needed around 40 seconds for images of size 25x25. The training curve is seen here (upper one is for binare images and lower one for non processed):
Source code:digitDatasetPath = fullfile(folder_save);
digitData = imageDatastore(digitDatasetPath,...
% _______________Begin Training_______________________%
trainingNumFiles = round(digitData.countEachLabel.Count.*1./5);
rng(1) % For reproducibility
[testDigitData,trainDigitData] = splitEachLabel(digitData,...
% splitEachLabel splits the image files in digitData into two new datastores, trainDigitData and testDigitData.
% Define the convolutional neural network architecture.
[trainImages,trainLabels] = digitTrain4DArrayData;
idx = randperm(size(trainImages,4),len);
valImages = trainImages(:,:,:,idx);
trainImages(:,:,:,idx) = ;
valLabels = trainLabels(idx);
trainLabels(idx) = ;
layers = [
imageInputLayer([new_sz new_sz 1])
options = trainingOptions('sgdm',...
convnet = trainNetwork(trainDigitData,layers,options);
time = toc;
YTest = classify(convnet,testDigitData);
TTest = testDigitData.Labels;
Y = classify(convnet,digitData);
T = digitData.Labels;
% Calculate the accuracy.
name_net = sprintf('dice_net_sz_%d',new_sz);
accuracy = sum(YTest == TTest)/numel(TTest);
acc = sum(Y == T)/numel(T);
fprintf('Test Accuracy is %d and the full accuracy %d\n', accuracy, acc);