observationDim should be either 2, 3, 4 or 5

7 次查看(过去 30 天)
Hi, sorry about noob question.
I am trying to adapt the TrainNetworkOnImageAndFeatureDataExample.mlx to my use case. I my use case I only have the training image data and the categories, the "X2Train" feature input is absent. Thus my layers now look as follows:
[h,w,numChannels,numObservations] = size(trainData);
numFeatures = 1;
numClasses = numel(categories(trainLabels));
imageInputSize = [h w numChannels];
filterSize = 5;
numFilters = 16;
layers = [
imageInputLayer(imageInputSize,Normalization="none")
convolution2dLayer(filterSize,numFilters)
batchNormalizationLayer
reluLayer
fullyConnectedLayer(50)
flattenLayer
fullyConnectedLayer(numClasses)
softmaxLayer
classificationLayer
];
%concatenationLayer(1,2,Name="cat")
lgraph = layerGraph(layers);
When running the trainNetwork I get an error:
observationDim should be either 2, 3, 4 or 5
But I have no clue whatsoever what I need to change here.

回答(1 个)

Sai Kiran
Sai Kiran 2023-3-6
Hi,
The error is due to mismatch in the dimensions of two matrices while multiplying them.
The layers doesn't have any errors when we pass another dataset.
Please check the dimensions of 'trainData' and 'trainLabels' and the command window , it shows where the error has occured at a specific line in the code.
I hope it helps!

类别

Help CenterFile Exchange 中查找有关 Sequence and Numeric Feature Data Workflows 的更多信息

标签

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by