How to solve this error?

7 vues (au cours des 30 derniers jours)
Arnav
Arnav le 4 Juil 2024
Déplacé(e) : Rik le 13 Juil 2024
Dear matlab team,
How to solve this error?
Invalid training data. For numeric array image input, predictors must be a 4-D array of images.
for this
trainedNet = trainNetwork(gaborResponses, imdsTrain.Labels, layers, options)
please guide us
  1 commentaire
Arnav
Arnav le 12 Juil 2024
Déplacé(e) : Walter Roberson le 12 Juil 2024
Dear sir,
I tried this code, but it resulted in error. As trial, I am using 3 class folders (1,2 and 3) with 10 gray images (total 30 images) of identical size 227x227x1 (of type uint8).
Also, We have created the network. The Gabor responses of size 227x227x4x30 have been computed on each 227x227 gray images (total 30 nos.) and on four orientations (gaborOrientation = [0 45 90 135];) and CNN layera number 25.
Prior to reshape statement, The size(gaborResponses) results in Gabor responses of size 227x227x4x30.
But when run
trainedNet = trainNetwork(gaborResponses, trainingImages.Labels, layers, options);
I still found this error
Invalid training data. For numeric array image input, predictors must be a 4-D array of images.
Pl. guide me to resolve the issue.

Connectez-vous pour commenter.

Réponses (1)

Garmit Pant
Garmit Pant le 5 Juil 2024
Hello Arnav
Given the function used and the error encountered, I gather that you are trying to train a neural network using the “trainNetwork function and are encountering an error because of the format of the input training data.
The “trainNetwork” function expects either a datastore, a numeric array or a table as the input for the predictor. Given the error, the ‘gaborResponses’ parameter is a numeric array. For 2-D images, the function expects a ‘h-by-w-by-c-by-N’ numeric array, where h, w, and c are the height, width, and number of channels of the images, respectively, and N is the number of images.
Check the dimensionality of ‘gaborResponses’ using the following code snippet:
size(gaborResponses)
If the input images are single channel images and ‘gaborResponses’ is 3-D numeric array, reshape it using the following code snippet:
gaborResponses = reshape(gaborResponses, height, width, 1, numberOfImages);
This shall help you eliminate the error.
Additionally, the “trainNetwork” function is not recommended for use. Instead, the “trainnet” function is recommended. For further understanding, refer to the documentation of the “trainnet” function:
I hope you find the above explanation and suggestions useful!
  5 commentaires
Walter Roberson
Walter Roberson le 11 Juil 2024
The most common cause of that message, is if gaborResponses needs to be transposed to match the length of the labels.
Arnav
Arnav le 13 Juil 2024
Déplacé(e) : Rik le 13 Juil 2024
Dear sir,
As trial, I am using 3 class folders (1,2 and 3) with 10 gray images (total 30 images) of identical size 227x227x1 (of type uint8).
We have chosen gaborSize = 15;
gaborOrientation = [0 45 90 135];
calculating value of thisX = 227x227 uint8 and ThisFilter = 4x1 cell
1x1 gabor
1x1 gabor
1x1 gabor
1x1 gabor
For this
numImages = numel(imdsTrain.Files);
gaborResponses = zeros(gaborSize, gaborSize, length(gaborOrientation), numImages);
for i = 1:numImages
image = readimage(imdsTrain, i);
for j = 1:length(gaborOrientation)
gaborFilters{j} = gabor(gaborSize, gaborOrientation(j));
for k = 1 : size(image, 4)
ThisFilter = gaborFilters(:, :, :, k);
thisX = image(:, :, :, k);
gaborResponse = convn(thisX, ThisFilter, 'same');
end
gaborResponses = reshape(gaborResponse,227,227,[]);
gaborResponses(:, :, j, i) = gaborResponse;
end
end
results in following Error using double
Conversion to double from cell is not possible.
Error in convn (line 30)
B = double(B);
Pl. guide me to resolve the issue.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Image Data Workflows dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by