京東金融大數據競賽豬臉識別(3)- 圖像特征提取之二
阿新 • • 發佈:2018-03-14
Alexnet 圖像特征 fc7 深度網絡既然在圖像識別方面有很高的準確率,那將某一層網絡輸出數據作為圖像特征也應該是可行的。該程序給出了使用Alexnet第七層作為激活層提取圖像特征的示例。代碼如下:
clear; trainPath = fullfile(pwd,‘image‘); trainData = imageDatastore(trainPath,... ‘IncludeSubfolders‘,true,‘LabelSource‘,‘foldernames‘); [trainingImages,testImages] = splitEachLabel(trainData,0.7,‘randomized‘); numTrainImages = numel(trainingImages.Labels); %加載預訓練模型 net = alexnet; %指定用來提取特征的層 layer = ‘fc7‘; %提取指定層訓練數據特征 trainingFeatures = activations(net,trainingImages,layer); %提取指定層測試數據特征 testFeatures = activations(net,testImages,layer); %獲取訓練數據標簽 trainingLabels = trainingImages.Labels; %獲取測試數據標簽 testLabels = testImages.Labels; save(‘alexnetFeature.mat‘,‘trainingFeatures‘,‘trainingLabels‘,‘trainingFeatures‘,‘testLabels‘);
相關內容可參看Matlab圖像識別/檢索系列(7)-10行代碼完成深度學習網絡之取中間層數據作為特征。
京東金融大數據競賽豬臉識別(3)- 圖像特征提取之二