CNN inputs and outputs are incorrect and I don't know why

4 visualizaciones (últimos 30 días)
Chris
Chris el 4 de Dic. de 2022
Comentada: Chris el 4 de Dic. de 2022
Hello, I've been trying to set up a CNN to predict the previous state in a Conway's Game of Life. Basically I've set up random boards with associated next step to train my neural network. The batchcreattion function simply creates board and run the game for one iteration. In that case I get a NxNxK array.
N = 20;
K = 10000;
[X,Y] = batchCreation(K,N);
layers = [
% Setup the inputs
imageInputLayer([N N 1])
% Five 5x5 filters
convolution2dLayer(5,5,'Padding','same')
batchNormalizationLayer
reluLayer
% Connect the output to the network
fullyConnectedLayer(N*N)
softmaxLayer % The results from the fully connected layer are converted to explicit probabilities by the soft max - it normalizes them to between 0 and 1
classificationLayer];
Xvalid = X(:,:,1:K/2);
Yvalid = Y(:,:,1:K/2);
options = trainingOptions('sgdm', ...
'InitialLearnRate',0.01, ...
'MaxEpochs',500, ...
'Shuffle','every-epoch', ...
'ValidationData',{Xvalid,Yvalid}, ...
'Plots','training-progress');
Xtrain = X(:,:,K/2:K);
Ytrain = Y(:,:,K/2:K);
net = trainNetwork(Xtrain,Ytrain,layers,options);
But for some reason I get the following message: `Error using trainNetwork Invalid training data. For classification tasks, responses must be a vector of categorical responses. For regression tasks, responses must be a vector, a matrix, or a 4-D array of numeric responses which must not contain NaNs.`
I'm really confused by how to set it up properly. Any help would be appreciated!

Respuestas (1)

Walter Roberson
Walter Roberson el 4 de Dic. de 2022
K = 10000;
[X,Y] = batchCreation(K,N);
We do not have that function, batchCreation, so we do not know at the moment what size(X) and size(Y) are.
Xtrain = X(:,:,K/2:K);
Ytrain = Y(:,:,K/2:K);
but we can see there that slightly over half of the third dimension is being selected (half would be K/2+1:K) . The result cannot possibly be a vector, because "vector" for the purposes of trainNetwork must be either a row vector or column vector.
The structure of the code hints that Y probably is not scalar in one of the first two dimensions, so Y(:,:,K/2:K) is probably either a full 3D or else has probably as two non-scalar dimensions. If it happens to be 1 x 1 x K then you should squeeze(Y(:,:,K/2:K))
  5 comentarios
Chris
Chris el 4 de Dic. de 2022
Well I am getting the same error `Invalid training data. For classification tasks, responses must be a vector of categorical responses. For regression tasks, responses must be a vector, a matrix, or a 4-D array of numeric responses which must not contain NaNs.`

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by