%% 学習済みnetworkと画像データのロード
load('trainednetwork.mat')
imdsValidation = imageDatastore('./validationdata/','IncludeSubfolders',true, ...
    'LabelSource','foldernames');

%% Data augmentation
augimdsValidation = augmentedImageDatastore([227,227,3],imdsValidation);

%% 推論の実行
[YPred,scores] = classify(netTransfer,augimdsValidation);
writematrix(scores,'scores.csv');
accuracy = mean(YPred == imdsValidation.Labels)

%% 混同行列
c1 = ones(1,75);
correct = [c1 c1*2 c1*3 c1*4 c1*5]; % 正解リスト
predict = double(YPred');
C = confusionmat(correct,predict);
figure
confusionchart(C)

%% Copyright 2022 Mutsumi Saito