MATLAB Answers

Imagedatastore can not find files

조회 수: 1(최근 30일)
Marina Ghobrial
Marina Ghobrial 2021년 7월 24일
댓글: Image Analyst 2021년 7월 24일
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
Image Analyst
Image Analyst 2021년 7월 24일
You're welcome. Glad it worked. Could you please click the "Accept this answer" link?

댓글을 달려면 로그인하십시오.

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by