Issues loading labels in Deep Network Analyzer
4 views (last 30 days)
Show older comments
Hello all,
I am configuring a neural network for keypoint detection. Each input is an image, and the label for each image is one single number. This number corresponds to a value in the xcoordinate of the image.
I have a table with the labels for my images, and I am assigning the right label to each image in the datastore by doing the following:
%ground truth is a table, pos_pixel is one of its cols, containing the
%label I need for that image
%the resulting img_datastore.Labels is an array of doubles
img_datastore.Labels(j) = ground_truth.pos_pixel(i);
After creating these labels, I go to "import custom data", and get the following:
"Invalid training data. The labels of the ImageDatastore must be a categorical vector."
Does anyone know why this could be happening? Thanks in advance.
Answers (1)
Aniketh
on 8 Jul 2023
Hi,
In the trainNetwork function, the response input (Labels) is expected to be a categorical array. However, in the provided code, the labels are assigned directly from a table column, and ends up as an array.
To resolve this issue, you need to convert the labels to a categorical vector using the categorical() function. To fix the problem, modify the code as follows:
img_datastore.Labels(j) = categorical(ground_truth.pos_pixel(i));
For more information you can read up on these pages:
Hope this was helpful!
2 Comments
Aniketh
on 10 Jul 2023
According to the documentation on imageDatastore, the lables can be of the type categorical | cell | logical | double | single | string, so probably what is happening here is when you load the images, it is assigning labels as the filenames, and not allowing you to change the datatype.
You can read more about how this works at imageDatastore. One workaround to this is using the combine function and use it to create a CombinedDatastore. You would have to store the labels as a datastore object to accomplish this, there is suffecient documentation on how to convert tabular/spreadsheets etc . It would require some extra work, but can be done.
Using imageDatastore give you a very abstracted view of these operations, and thus provides less customizability such as labelling images directly through tables, hope this helped!
See Also
Categories
Find more on Image Data Workflows in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!