MATLAB學(xué)習(xí)help之——Classify Image Using GoogLeNet from Neural Network Toolbox

這一個例子是利用已經(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
原圖如下


圖片.png

重置后


圖片.png

Step 3.
分類圖片

[label,scores] = classify(net,I);
label

得到


圖片.png

顯示圖片并計算概率

figure
imshow(I)
title(string(label) + ", " + num2str(100*scores(classNames == label),3) + "%");
圖片.png

顯示概率前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)
圖片.png

總結(jié):

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


圖片.png
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容