How to train neural network with extracted features?

5 visualizzazioni (ultimi 30 giorni)
I use following code for feature detection aand storing:
srcFiles = dir('E:\Database\Preprocessed\Genuine\Resize\20\*.png'); % the folder in which ur images exists
Features = cell(length(srcFiles),1) ;
Valid_points =cell(length(srcFiles),1) ;
for i = 1 : length(srcFiles)
filename = strcat('E:\Database\Preprocessed\Genuine\Resize\20\',srcFiles(i).name);
points1 = detectSURFFeatures(imread(filename)); hold on;
strongest = points1.selectStrongest(5);
imshow(filename); hold on;
plot(strongest);
strongest.Location
[features1, interest_points] = extractFeatures(imread(filename), points1);
Features{i} = features1 ;
Valid_points{i} = interest_points ;
figure; imshow(filename);
end
%Features;
%Valid_points;
plz tell me how to give the input of extracted features in the training of neural network.

Risposte (1)

Shantanu Dixit
Shantanu Dixit il 21 Feb 2025
Hi Regina,
If I understand your query correctly, you want to use the 'SURF' features you've extracted (stored in cell arrays) as inputs to a neural network. Neural network training functions in MATLAB typically require a numeric matrix where each sample has a fixed length. Since each image might produce a variable number of feature vectors, you can aggregate these into a single feature vector per image.
One common approach is to summarize the features from each image using the mean of the feature vectors. Then, you can form a matrix where each column (or row) represents one image’s feature vector.
  • Aggregation: Computing the mean of the feature vectors from each image to get a fixed-length representation. You can also experiment with other methods (like selecting strongest features).
  • Input Matrix: The matrix 'X' becomes your training input, where each column is a feature vector for one image.
  • Targets: The matrix 'T' holds the corresponding one-hot encoded labels for supervised training.
You can refer to the below MATLAB snippet for aggregating the features and preparing the data for neural network training:
% Suppose 'Features' is a cell array where each cell contains a matrix
% of SURF feature vectors for an image.
numImages = length(Features);
featureDim = size(Features{1},2);
X = zeros(featureDim, numImages); % Preallocate matrix X to hold one feature vector per image
% Aggregate features for each image (using the mean here)
for i = 1:numImages
X(:,i) = mean(Features{i}, 1)';
end
% labels
numClasses = 2;
T = zeros(numClasses, numImages);
for i = 1:numImages
if labels(i) == 1
T(:,i) = [1; 0];
else
T(:,i) = [0; 1];
end
end
% Training using a pattern recognition network:
hiddenLayerSize = 10;
net = patternnet(hiddenLayerSize);
net = train(net, X, T);
Additionally you can also refer to the following useful MathWorks documentation on training neural networks:
Hope this helps!

Categorie

Scopri di più su Deep Learning Toolbox in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by