Clear Filters
Clear Filters

observationDim should be either 2, 3, 4 or 5

7 views (last 30 days)
Marc Dirix
Marc Dirix on 2 Mar 2023
Answered: Sai Kiran on 6 Mar 2023
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.

Answers (1)

Sai Kiran
Sai Kiran on 6 Mar 2023
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!

Categories

Find more on Sequence and Numeric Feature Data Workflows in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!