how to set input for fully connected layer
3 次查看(过去 30 天)
显示 更早的评论
Hello. I extracted features from video dataset and saved them in a cell. Because each video has different number of frames, size of feature matrixes are different (plz see the attached picture). I want to use these features as input for net_fc in last line of following code, but this error happens: ''Error using trainNetwork invalid training data. Responses must be a vector of categorical responses, or a cell array of categorical response sequences. can any one plz help me to set my input for the nt_fc? thanks so much...![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/319615/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/319615/image.png)
clc;clear;close
DD = load( 'D:\simulation\ALL1\TRAIN_DATA_taranhade.mat');
sequences = DD.sequences;
YTrain = ['a'; 'a'; 'a'; 'a'; 'a'; 'a';...
'b'; 'b'; 'b'; 'b'; 'b'; 'b';...
'c'; 'c'; 'c'; 'c'; 'c'; 'c';...
'd'; 'd'; 'd'; 'd'; 'd'; 'd';...
'e'; 'e'; 'e'; 'e'; 'e'; 'e';...
'f'; 'f'; 'f'; 'f'; 'f'; 'f';...
'g'; 'g'; 'g'; 'g'; 'g'; 'g';...
'h'; 'h'; 'h'; 'h'; 'h'; 'h'];
numObservations = numel(sequences);
idx = randperm(numObservations);
N = floor(0.9 * numObservations);
idxTrain = idx(1:N);
sequencesTrain = sequences(idxTrain);
labelsTrain = YTrain(idxTrain);
idxValidation = idx(N+1:end);
sequencesValidation = sequences(idxValidation);
labelsValidation = YTrain(idxValidation);
numFeatures = size(sequencesTrain{1},1);
numClasses = 8;%numel(categories((labelsTrain)));
% analyzeNetwork
layers = [
sequenceInputLayer(numFeatures,'Name','sequence')
fullyConnectedLayer(128,'Name','fc1');
reluLayer
fullyConnectedLayer(numClasses);
reluLayer
softmaxLayer('Name','soft1')
classificationLayer('Name','classification')];
miniBatchSize = 16;
numObservations = numel(sequencesTrain);
numIterationsPerEpoch = floor(numObservations / miniBatchSize);
options = trainingOptions('adam', ...
'MiniBatchSize',miniBatchSize, ...
'InitialLearnRate',1e-4, ...
'GradientThreshold',2, ...
'Shuffle','every-epoch', ...
'ValidationData',{sequencesValidation,labelsValidation}, ...
'ValidationFrequency',numIterationsPerEpoch, ...
'Plots','training-progress', ...
'Verbose',false);
net_fc = trainNetwork(sequencesTrain,labelsTrain,layers,options);
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Data Workflows 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!