Filter löschen
Filter löschen

partial face recognition using CNN-alexnet

3 Ansichten (letzte 30 Tage)
Munshida P
Munshida P am 9 Mär. 2020
Kommentiert: Munshida P am 19 Mär. 2020
an arror occured while implementing face recognition using CNN -alexnet.please help me to move the project.
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);
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);

Antworten (1)

Srivardhan Gadila
Srivardhan Gadila am 16 Mär. 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]);
Alternatively you can load the images using imageDatastore and then use the augmentedImageDatastore for resizing the images.
  1 Kommentar
Munshida P
Munshida P am 19 Mär. 2020
okey sir....Thank you. I will implement and will be back with the results...

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by