imageDatastore multiple output label
18 次查看(过去 30 天)
显示 更早的评论
I have created a structure that has the file name, feature/image folder location, and the labeling vector.
My project involves taking a spectrogram image of a musical triad which has three output labels/notes which I have stored as [2;35;66]...[15;23;71].
I cannot add all three labels to a single row of the cell inside the imageDatastore the closest I can is add an Nx1 vector of the first note in the musical triad but not when I try imds.Labels = [Note1Vector ; Note2Vector; Note3Vector] it will give me the error:
Error using indexing
Labels must be a string array, or a cell array of character vectors, or a vector of numeric, logical, or categorical
type.
Thank you.
1 个评论
Yash
2024-1-15
Hi Chaz,
Kindly share a sample code with some data to better understand and reproduce the issue that you are facing.
回答(1 个)
Yash
2024-1-18
Hi Chaz,
It seems like you're trying to work with MATLAB's "imageDatastore" to handle a multi-label classification problem, where each image has multiple labels associated with it. The default behavior of "imageDatastore" is to handle single-label scenarios, where each image is associated with one label. However, for multi-label classification, you need to store the labels in a format that "imageDatastore" can accept.
Since "imageDatastore" expects the labels to be a single array or vector, you cannot directly assign a matrix of labels where each image has multiple labels. Instead, you should consider using a cell array where each cell contains the vector of labels for the corresponding image.
Here's how you can structure your labels and assign them to the imageDatastore:
% Assume you have an imageDatastore 'imds' already created with the images loaded
% And you have your labels in the format [2;35;66], [15;23;71], etc.
% Let's say 'labelMatrix' is an Nx3 matrix where each row corresponds to the labels of an image
labelMatrix = [
2, 35, 66;
15, 23, 71;
% ... and so on for all your images
];
% Convert this matrix to a cell array where each cell contains a vector of the labels
labelCellArray = num2cell(labelMatrix, 2);
% Assign this cell array to the Labels property of your imageDatastore
imds.Labels = labelCellArray;
This way, each image will have a cell with a numeric vector corresponding to its labels. When you train your model, you'll need to make sure it can handle this kind of multi-label input. Depending on the deep learning framework you're using (like MATLAB's Deep Learning Toolbox), you might need to customize the data input layer or the loss function to properly handle multi-label targets.
If you still face the issue, kindly share a sample code with some data to better understand and reproduce the issue that you are facing.
Hope this helps!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Recognition, Object Detection, and Semantic Segmentation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!