Error using trainNetwork . Number of observations in X and Y disagree

112 views Asked by At

I'm trying to train a neural network but get

Error using trainNetwork. Number of observations in X and Y disagree.

I am not able to understand where is the problem. XTrain is a 607x39x367x1 double and loadYTrain is 607x1 double (before training i changed to categorical also.).

Here is my code:

layers = [
    imageInputLayer([39 367 1])
    convolution2dLayer(3, 32, 'Padding', 'same')
    reluLayer
    convolution2dLayer(3, 64, 'Padding', 'same')
    reluLayer
    maxPooling2dLayer(2, 'Stride', 2)
    dropoutLayer(0.2)
    fullyConnectedLayer(128)
    reluLayer
    dropoutLayer(0.2)
    fullyConnectedLayer(64)
    reluLayer
    fullyConnectedLayer(15)
    softmaxLayer
    classificationLayer];
% Set training options
options = trainingOptions('adam', ...
    'MaxEpochs', 20, ...
    'MiniBatchSize', 16, ...
    'InitialLearnRate', 0.0001, ...
    'ValidationData', {test_data, test_labels_categorical}, ...
    'Plots', 'training-progress');
train_labels_categorical = categorical(train_labels);
% Train the model
trained_model = trainNetwork(train_data, train_labels_categorical, layers, options);

My MATLAB version is 2020b

0

There are 0 answers