Imagedatastore can not find files

40 次查看(过去 30 天)
Hi,
I keep getting the following errors when I run this code.
"Error using imageDatastore (line 138)
Cannot find files or folders matching: 'photos\x'."
I was trying to use ANN to be able to tell different categories. However, for some reason matlab is not reading my images. I tried different methods such as dividing the code down to multiple imds such as
% imds1 = imageDatastore('C:\Users\OneDrive\Desktop\photos\x', 'FileExtensions',{'.HEIC'})
% imds2 = imageDatastore('C:\Users\OneDrive\Desktop\photos\y','FileExtensions',{'.HEIC'})
% imds3 = imageDatastore('C:\Users\OneDrive\Desktop\photos\z','FileExtensions',{'.HEIC'})
% imds4 = imageDatastore('C:\Users\OneDrive\Desktop\photos\a','FileExtensions',{'.HEIC'})
% imds5 = imageDatastore('C:\Users\OneDrive\Desktop\photos\b','FileExtensions',{'.HEIC'})
which was able to read the photos but was not able to determine which category it belonged to.
The code is:
categories = {'x','y','z','a','b'};
rootFolder = 'photos';
imds = imageDatastore (fullfile(rootFolder, categories), ...
'LabelSource',"foldernames", 'IncludeSubfolders',true);
Please Help, Thank you in advance!

采纳的回答

Image Analyst
Image Analyst 2021-7-24
编辑:Image Analyst 2021-7-24
Did you look at what the fullfile() returns? Let's pull it out separately and see
categories = {'x','y','z','a','b'};
rootFolder = 'photos';
filePattern = fullfile(rootFolder, categories)
imds = imageDatastore(filePattern, ...
'LabelSource',"foldernames", 'IncludeSubfolders',true);
We see
ans =
1×5 cell array
{'photos\x'} {'photos\y'} {'photos\z'} {'photos\a'} {'photos\b'}
so as you can see, those are not full folder names with drive and everything, so it's not able to find the files.
  4 个评论
Marina Ghobrial
Marina Ghobrial 2021-7-24
yes, it worked. Thank you so much for all your help!
Image Analyst
Image Analyst 2021-7-24
You're welcome. Glad it worked. Could you please click the "Accept this answer" link?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Entering Commands 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by