regarding label source names in data set imagedatastore

i am working on image classification problem .I am using dataset in which there are some parent folder.Each parent folder have some sub folders.And these subfolders contain the image data.when i use imagedatastore to load ,it takes subfolder as class
I want to take parent folder as class(all the folder in that parent folder sould be a class named as parent folder name).
how to do this .

回答 (2 件)

Johanna Pingel
Johanna Pingel 2019 年 2 月 12 日

2 投票

ImageDatastore works really well if you have a parent class and 1 sub folder per class.
imageDatastore('parentfolder/','IncludeSubFolders',true','LabelSource','foldernames');
If not, you may have to do a little more processing. I'm sure there's a ton of ways to accomplish this: I would suggest getting all of your images and labels for each class into a datastore
class1 = imageDatastore({'cat1/random_folder/','cat1/'});
class1.Labels = repelem("cat1",numImages);
Do this for each class, then combine them into one super datastore
imdsFinal = imageDatastore([class1.Files; class2.Files]);
imdsFinal.Labels = [class1.Labels; class2.Labels]);
This should work and be able to customize to what you're trying to do!

9 件のコメント

ghada ebrahim
ghada ebrahim 2020 年 2 月 25 日
please i want to know what 'cat1/random_folder/' refer to?
Johanna Pingel
Johanna Pingel 2020 年 2 月 26 日
cat1 would stand for category 1, as in: a folder with images of category1 in it. This could be any name of your folder for this problem, since this is a hypothetical answer.
random_folder refers to any subfolders which also contain images of category 1.
I believe this was the question posed on how to get all images from folders and subfolders for a category.
ghada ebrahim
ghada ebrahim 2020 年 2 月 26 日
i get it, thank you so much
Nilu R Salim
Nilu R Salim 2020 年 3 月 4 日
編集済み: Nilu R Salim 2020 年 3 月 4 日
Hi,
I tried this out. But it's not working.. it repeatedly throws an error. Let me elaborate the issue that I face. I have a main folder with 80 subfolders. Each of the subfolder has 6 more folders in it. I want the labels to be "80". How is it possible?
Nilu R Salim
Nilu R Salim 2020 年 3 月 4 日
I would really appreciate a quick reply Thanks in advance.
Nilu R Salim
Nilu R Salim 2020 年 3 月 4 日
I would like to have it something similar to "cd .."
OJ27
OJ27 2020 年 8 月 18 日
The code worked for me except for this part
imdsFinal.Labels = [class1.Labels; class2.Labels]);
That line should be replaced with
imdsFinal.Labels = [categorical(class1.Labels); categorical(class2.Labels)]);
Otherwise, you would have a cell array containing strings rather than categorical. After you merge both imageDatastore, then you can call
categories(imdsFinal.Labels)
to check the labels in the dataset.
AYUSH ANAND SAGAR
AYUSH ANAND SAGAR 2020 年 10 月 27 日
i want to display the found image's label as the output
how can i do that?
aref
aref 2022 年 8 月 23 日
labels= unique(trainingData.Labels);

サインインしてコメントする。

Neslihan
Neslihan 2023 年 4 月 27 日

0 投票

Dataset = imageDatastore('Dataset', 'IncludeSubfolders', true, 'LabelSource', 'foldernames');

カテゴリ

タグ

質問済み:

2019 年 2 月 10 日

回答済み:

2023 年 4 月 27 日

Community Treasure Hunt

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

Start Hunting!

Translated by