partial face recognition using CNN-alexnet

4 vues (au cours des 30 derniers jours)
Munshida P
Munshida P le 9 Mar 2020
Commenté : Munshida P le 19 Mar 2020
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);
>>

Réponses (1)

Srivardhan Gadila
Srivardhan Gadila le 16 Mar 2020
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 commentaire
Munshida P
Munshida P le 19 Mar 2020
okey sir....Thank you. I will implement and will be back with the results...

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by