Issues loading labels in Deep Network Analyzer

2 次查看(过去 30 天)
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.
  1 个评论
Fred Severgnini
Fred Severgnini 2023-6-23
additionally, here's how I'm creating the datastore:
img_datastore = imageDatastore('C:\Users\Admin\Desktop\keypoint_inputs\2022_11_16c\images');

请先登录,再进行评论。

回答(1 个)

Aniketh
Aniketh 2023-7-8
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 个评论
Fred Severgnini
Fred Severgnini 2023-7-10
Hello Aniketh,
Thank you for your answer.
Upon further inspection, it seems my main issue is that the system is expecting the output to be categories only (i.e. to classify elements in images as being birds, dogs etc).
The network I am trying to build is supposed to output a number, which is the x-axis coordinate of an element in the image.If the system receives the coordinates as categories, this will compromise the loss calculations.
Do you know if there is a way to change this expected output?
Aniketh
Aniketh 2023-7-10
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!

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Image Data Workflows 的更多信息

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by