How can I apply PCA on thousand of images to reduce the dimension of the data?

4 次查看(过去 30 天)
Hi,
I applied a simple CNN on dataset of 1000 images and the code works fine. However, I want to apply PCA on both training and testing set in order to reduce reduce its dimensionality (features selection) the code is below. Many thanks.
close all
clear all
clc
%% Load image data
imds = imageDatastore('the path of images folder',...
'IncludeSubfolders',true,'LabelSource','foldernames')
tbl = countEachLabel(imds)
%% Divide the data into 70% training data and 30% validation data
[imdsTrain,imdsValidation] = splitEachLabel(imds,0.7,'randomized');
%% Specify training options.
options = trainingOptions('sgdm', ...
'MiniBatchSize',10, ...
'MaxEpochs',3, ...
'Shuffle','every-epoch', ...
'InitialLearnRate',1e-4, ...
'ValidationData',imdsValidation, ...
'ValidationFrequency',6, ...
'Verbose',false, ...
'Plots','training-progress', ...
'ExecutionEnvironment','gpu');
%% Layers for simple CNN.
layers_1 = [
imageInputLayer([512 512 1])
convolution2dLayer(3,8,'Padding','same')
batchNormalizationLayer
reluLayer
maxPooling2dLayer(2,'Stride',2)
convolution2dLayer(3,16,'Padding','same')
batchNormalizationLayer
reluLayer
maxPooling2dLayer(2,'Stride',2)
convolution2dLayer(3,32,'Padding','same')
batchNormalizationLayer
reluLayer
fullyConnectedLayer(2)
softmaxLayer
classificationLayer];
%% train the network
netTransfer = trainNetwork(imdsTrain,layers_1,options);

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Dimensionality Reduction and Feature Extraction 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by