function accuracy = evaluation(net, imdb)
%This function evaluates the network on the test images (set == 3) and
%calculates the mean accuracy.

%get the test images and the corresponding labels
cifar_test_imgs = imdb.images.data(:,:,:,imdb.images.set==3);
cifar_test_labels = imdb.images.labels(imdb.images.set==3);

%set the network to test mode (replace the final softmaxloss layer to a softmax layer)
net.layers{end} = struct('type', 'softmax') ;
net = vl_simplenn_tidy(net);

%evlauate the images with the trained network
res = vl_simplenn(net, cifar_test_imgs, [], [], 'mode', 'test');

%get the prediced labels
[~, pred_labels] = max(squeeze(res(end).x));

%calculate precision
accuracy = mean(cifar_test_labels == pred_labels);
fprintf('\nAccuracy on the %d test images: %f\n', length(pred_labels), accuracy);
