Imagedatastore can not find files

18 views (last 30 days)
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!

Accepted Answer

Image Analyst
Image Analyst on 24 Jul 2021
Edited: Image Analyst on 24 Jul 2021
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.
Image Analyst
Image Analyst on 24 Jul 2021
You're welcome. Glad it worked. Could you please click the "Accept this answer" link?

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!