摘要:本篇教程介绍了大数据应用 京东金融大数据竞赛猪脸识别(9)- 识别方法之五,希望阅读本篇文章以后大家有所收获,帮助大家对大数据云计算大数据应用的理解更加深入。
本篇教程介绍了大数据应用 京东金融大数据竞赛猪脸识别(9)- 识别方法之五,希望阅读本篇文章以后大家有所收获,帮助大家对大数据云计算大数据应用的理解更加深入。
<
这里给出使用深度网络中间层输出结果作为图像特征,并构建分类模型和对训练数据进行识别的代码。代码如下:
clear
trainPath = fullfile(pwd,'image');
trainData = imageDatastore(trainPath,...
'IncludeSubfolders',true,'LabelSource','foldernames');
%对训练数据集进行划分
[trainingImages,testImages] = splitEachLabel(trainData,0.7,'randomized');
numTrainImages = numel(trainingImages.Labels);
%设定要加载的预训练模型
% net1 = googlenet;
% net2 = vgg16;
% net = vgg19;
net = alexnet;
layer = 'fc7';
%提取第7层网络输出数据
trainingFeatures = activations(net,trainingImages,layer);
testFeatures = activations(net,testImages,layer);
trainingLabels = trainingImages.Labels;
testLabels = testImages.Labels;
%训练多分类模型
classifier = fitcecoc(trainingFeatures,trainingLabels, 'FitPosterior',1);
%预测数据的类别
predictedLabels = predict(classifier,testFeatures);
[label,NegLoss,PBScore,Posterior] = predict(classifier,testFeatures);
idx = [1 5 10 15];
figure
for i = 1:numel(idx)
subplot(2,2,i)
I = readimage(testImages,idx(i));
label = predictedLabels(idx(i));
imshow(I);
title(char(label));
end
%计算准确率
accuracy = mean(predictedLabels == testLabels);
该方法在csv文件上传后得分在1左右,排名约在前8%。这段代码不是比赛用的完整代码,不过用法类似。
本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注职坐标大数据云计算大数据应用频道!
您输入的评论内容中包含违禁敏感词
我知道了
请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号