這一個例子是利用已經(jīng)訓(xùn)練好的深度學(xué)習(xí)網(wǎng)絡(luò), GoogLeNet, 其具體的解釋詳見另一篇轉(zhuǎn)載的博客。
GoogLeNet has been trained on over a million images and can classify images into 1000 object categories (such as keyboard, coffee mug, pencil, and many animals). The network has learned rich feature representations for a wide range of images. The network takes an image as input and outputs a label for the object in the image together with the probabilities for each of the object categories.
Step 1.
加載深度學(xué)習(xí)網(wǎng)絡(luò), 并查看輸入層的大小。
net = googlenet;
inputSize = net.Layers(1).InputSize
得到
inputSize =
224 224 3
網(wǎng)絡(luò)層的最后一個層為輸出層,隨機查看1000種分類中的10個
classNames = net.Layers(end).ClassNames;
numClasses = numel(classNames);
disp(classNames(randperm(numClasses,10)))
得到
'speedboat'
'window screen'
'isopod'
'wooden spoon'
'lipstick'
'drake'
'hyena'
'dumbbell'
'strawberry'
'custard apple'
Step2.
載入圖片并重置尺寸
I = imread('peppers.png');
figure
imshow(I)
size(I)
I = imresize(I,inputSize(1:2));
figure
imshow(I)
得到
ans =
384 512 3
原圖如下

重置后

Step 3.
分類圖片
[label,scores] = classify(net,I);
label
得到

顯示圖片并計算概率
figure
imshow(I)
title(string(label) + ", " + num2str(100*scores(classNames == label),3) + "%");

顯示概率前5的分類結(jié)果
[~,idx] = sort(scores,'descend');
idx = idx(5:-1:1);
classNamesTop = net.Layers(end).ClassNames(idx);
scoresTop = scores(idx);
figure
barh(scoresTop)
xlim([0 1])
title('Top 5 Predictions')
xlabel('Probability')
yticklabels(classNamesTop)

總結(jié):
主要學(xué)習(xí)了 如何 調(diào)用已經(jīng)訓(xùn)練好的 深度學(xué)習(xí)網(wǎng)絡(luò) googlenet, 對于另外的深度學(xué)習(xí)網(wǎng)絡(luò),方法相同
如
