File size: 1,248 Bytes
5fa9817 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
function [accuracy, confusion_matrix] = eval_train(pred_fname)
% Evaluates training accuracy.
% Arguments:
% pred_fname: Filename of prediction file for training. The required format
% is described in the README.
% Returns:
% accuracy: The accuracy on the training set.
% confusion_matrix: The confusion matrix on the training set.
accuracy = [];
confusion_matrix = [];
train_data = load('cars_train_annos.mat');
train_annos = train_data.annotations;
train_classes = [train_annos.class];
unique_classes = unique(train_classes);
try
preds = csvread(pred_fname);
catch err
fprintf('Invalid file format for input file %s.', pred_fname);
return
end
% Check whether predictions look sane
if numel(preds) ~= numel(train_classes)
fprintf(['Given predictions have length %d but there are %d images ' ...
'in the training set.\n'], numel(preds), numel(train_classes));
return;
elseif any(~ismember(preds, unique_classes))
bad_ind = find(~ismember(preds, unique_classes), 1);
fprintf(['Predicted class for image %d is %d, which is an invalid ' ...
'class.\n'], bad_ind, preds(bad_ind));
return;
end
% Evaluate
accuracy = mean(preds(:) == train_classes(:));
confusion_matrix = confusionmat(train_classes(:), preds(:));
|