-
Notifications
You must be signed in to change notification settings - Fork 75
/
exercise5.m
31 lines (24 loc) · 1.04 KB
/
exercise5.m
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
function exercise5()
% EXERCISE5 Part 5 of the VGG CNN practical
setup ;
% -------------------------------------------------------------------------
% Part 5.1: load a pretrained model
% -------------------------------------------------------------------------
net = load('data/imagenet-vgg-verydeep-16.mat') ;
vl_simplenn_display(net) ;
% -------------------------------------------------------------------------
% Part 5.2: use the model to classify an image
% -------------------------------------------------------------------------
% obtain and preprocess an image
im = imread('peppers.png') ;
im_ = single(im) ; % note: 255 range
im_ = imresize(im_, net.meta.normalization.imageSize(1:2)) ;
im_ = bsxfun(@minus,im_,net.meta.normalization.averageImage) ;
% run the CNN
res = vl_simplenn(net, im_) ;
% show the classification result
scores = squeeze(gather(res(end).x)) ;
[bestScore, best] = max(scores) ;
figure(1) ; clf ; imagesc(im) ; axis image ;
title(sprintf('%s (%d), score %.3f',...
net.meta.classes.description{best}, best, bestScore)) ;