Number of observations in X and Y disagree

3 views (last 30 days)
Hello! Sorry for my English, but I really need help.
I'm trying to create my first neural network that will be a noise filter on an image. The idea is to walk through the image with a sliding window, and submit to the input of the neural network the brightness values of the central pixel and its surroundings in the sliding window (in the image with noise). And also input the brightness value of the desired pixel from the test image (without noise).
My code:
layers = [ ...
imageInputLayer([1 9 1])
convolution2dLayer(1,3)
reluLayer
fullyConnectedLayer(1)
regressionLayer];
options = trainingOptions('sgdm', ...
'InitialLearnRate',0.001, ...
'Verbose',false, ...
'Plots','training-progress');
net = trainNetwork(X,Y,layers,options);
Where X is an array of size 813604 by 9, and Y is 813604 by 1. Each row of the array is the values from the sliding window.
I get an error: "Number of observations in X and Y disagree", and I don't understand how to fix it.

Answers (1)

Cris LaPierre
Cris LaPierre on 23 Feb 2023
It would be helpful if you could share your data, or at least a representative subsample of it. You can attach it to your post using the paperclip icon.
You appear to be following this example, so the issue appears to be the structure of your X data. We don't know what it is, but take a look at this table from the trainnetwork documentation (under sequences) for what is expected.
  • Vector sequences: c-by-s matrices, where c is the number of features of the sequences and s is the sequence length.
  • 1-D image sequences: h-by-c-by-s arrays, where h and c correspond to the height and number of channels of the images, respectively, and s is the sequence length.
  • 2-D image sequences: h-by-w-by-c-by-s arrays, where h, w, and c correspond to the height, width, and number of channels of the images, respectively, and s is the sequence length.
  • 3-D image sequences: h-by-w-by-d-by-c-by-s, where h, w, d, and c correspond to the height, width, depth, and number of channels of the 3-D images, respectively, and s is the sequence length.

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!