partial face recognition using CNN-alexnet

8 ビュー (過去 30 日間)
Munshida P
Munshida P 2020 年 3 月 9 日
コメント済み: Munshida P 2020 年 3 月 19 日
an arror occured while implementing face recognition using CNN -alexnet.please help me to move the project.
clc
clear
n=1;
im = imageDatastore('images','IncludeSubfolders',true,'LabelSource','foldernames');
% Resize the images to the input size of the net
im.ReadFcn = @(loc)imresize(imread(loc),[227,227]);
[Train ,Test] = splitEachLabel(im,0.8,'randomized');
fc = fullyConnectedLayer(n);
net = alexnet;
ly = net.Layers;
ly(23) = fc;
cl = classificationLayer;
ly(25) = cl;
% options for training the net if your newnet performance is low decrease
% the learning_rate
learning_rate = 0.00001;
opts = trainingOptions("rmsprop","InitialLearnRate",learning_rate,'MaxEpochs',5,'MiniBatchSize',64,'Plots','training-progress');
[newnet,info] = trainNetwork(Train, ly, opts);
[predict,scores] = classify(newnet,Test);
names = Test.Labels;
pred = (predict==names);
s = size(pred);
acc = sum(pred)/s(1);
fprintf('The accuracy of the test set is %f %% \n',acc*100);
%%%%ERROR%%%%
Training on single CPU.
Initializing input data normalization.
Error using trainNetwork (line 170)
Unexpected image size: All images must have the same size.
Error in work2 (line 21)
[newnet,info] = trainNetwork(Train, ly, opts);
>>

回答 (1 件)

Srivardhan Gadila
Srivardhan Gadila 2020 年 3 月 16 日
Make sure that all the images have the same number of channels.
Make use of the following:
im = imageDatastore('images','IncludeSubfolders',true,'LabelSource','foldernames');
im.ReadFcn = @customReadDatstoreImage;
function data = customReadDatastoreImage(filename)
% code from default function:
onState = warning('off', 'backtrace');
c = onCleanup(@() warning(onState));
data = imread(filename); % added lines:
data = data(:,:,min(1:3, end));
data = imresize(data,[227 227]);
end
Alternatively you can load the images using imageDatastore and then use the augmentedImageDatastore for resizing the images.
  1 件のコメント
Munshida P
Munshida P 2020 年 3 月 19 日
okey sir....Thank you. I will implement and will be back with the results...

サインインしてコメントする。

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by