我不知道哪裡打錯cannot find files or folders matching

imds=imageDatastore('D:/fruit','IncludeSubfolders',true,'LabelSource','foldernames
我有5張水果圖片存在d槽,總檔名就叫fruit,可是哪裡錯了?

1 Comment

Cannot find files or folders matching: 'D:\fruit'.是因為這個總檔名的內容沒有東西,所以它找不到我的檔名嗎?

Sign in to comment.

 Accepted Answer

You are telling it that there are folders (not files) inside D:\Fruit. Are there? Maybe if there are no subfolders it will throw that error. What does this show in the command window?
>> ls('D:\Fruit')
If you see just files and . and .. then that could be the problem. You're supposed to have folders that have the name of the class labels you want to detect in your images with your deep learning program.

5 Comments

是因為深度學習沒有檔案才找不到嗎?
That's not what I asked for. I don't know what that image you posted is for.
I was asking to see what subfolders were under \Fruit, like grape, banana, strawberry, apple, orange, lemon, lime, kiwi, raspberry, blueberry, blackberry, etc.
你說的是著個嗎?
what was the result of https://www.mathworks.com/matlabcentral/answers/1825303-cannot-find-files-or-folders-matching#comment_2415163
結果就是最簡單的水果辯試,但是就是檔案跑不出來圖片,不知道怎麼試就是找不到'D:\Fruit這個檔案。

Sign in to comment.

More Answers (2)

Rani
Rani on 13 Oct 2022
Edited: Rani on 13 Oct 2022
Hi,
Please refer to the linked documentation for more info about the syntax on "imageDataStore":

7 Comments

imds=imageDatastore('D:\fruit\apple\banana\guava\kiwi\lemon','IncludeSubfolders',true,'LabelSource','foldernames');
都試了不知道哪裡錯了,看了你給的網站,不是很懂。
That would not work if you are trying to look for D:\fruit\apple D:\fruit\banana D:\fruit\guava D:\fruit\kiwi D:\fruit\lemon . However,
exts = {'.jpg'};
imds = imageDatastore('D:\fruit', 'IncludeSubfolders', true, 'LabelSource', 'foldernames', 'FileExtensions', exts);
should work (adjust exts as appropriate for your situation.)
所以存在D槽也一樣嗎,用了這個複製,Cannot find files or folders matching: 'D:\fruit'.,還是找不到,可是我用的就是fruit總檔名,但就是不知道它為什麼就是找不到。
Please show the output of
ls('D:\')
這是我完整的程式碼,哪裡有錯?
layers=[
imageInputLayer([227 227 3],"Name","imageinput")
convolution2dLayer([3 3],32,"Name","conv_4","Padding","same")
reluLayer("Name","relu_4")
maxPooling2dLayer([5 5],"Name","maxpool","Padding","same")
convolution2dLayer([3 3],32,"Name","conv_6","Padding","same")
reluLayer("Name","relu_6")
fullyConnectedLayer(5,"Name","br")
softmaxLayer("Name","brian076269")
classificationLayer("Name","classoutput")];
plot(layerGraph(layers));
exts = { '.jpg' };
imds = imageDatastore( 'D:\fruit' , 'IncludeSubfolders' , true, 'LabelSource' , 'foldernames' , 'FileExtensions' , exts);
options=trainingOptions('adam''Maxepoches',4,'intiaLearnRate',0.0001);
convnet=trainNetwork(imds,layers,options);
inp='D:/fruit/01.jpg/02.pg/03.jpg/04.jpg/05.jpg';
I=imread(inp);
figure,imshow(I)
% % %done classification
class=classify(convnet,I);
msgbox(char(class))
不太會看哪個是輸出,是哪個inp嗎?
inp='D:/fruit/01.jpg/02.pg/03.jpg/04.jpg/05.jpg';
Instead
projectdir = 'D:\Fruit';
for K = 1 : 5
inp = sprintf('%02d.jpg', K);
I = imread( fullfile(projectdir, inp) );
figure, imshow(I);
class = classify(convnet, I);
t = sprintf('file %s classified as %s', inp, string(class));
title(t);
end

Sign in to comment.

In some cases, folder names are case sensitive
projectdir = 'D:\Fruit';
layers=[
imageInputLayer([227 227 3],"Name","imageinput")
convolution2dLayer([3 3],32,"Name","conv_4","Padding","same")
reluLayer("Name","relu_4")
maxPooling2dLayer([5 5],"Name","maxpool","Padding","same")
convolution2dLayer([3 3],32,"Name","conv_6","Padding","same")
reluLayer("Name","relu_6")
fullyConnectedLayer(5,"Name","br")
softmaxLayer("Name","brian076269")
classificationLayer("Name","classoutput")];
plot(layerGraph(layers));
exts = { '.jpg' };
imds = imageDatastore( projectdir, 'IncludeSubfolders' , true, 'LabelSource' , 'foldernames' , 'FileExtensions' , exts);
options=trainingOptions('adam''Maxepoches',4,'intiaLearnRate',0.0001);
convnet=trainNetwork(imds,layers,options);
for K = 1 : 5
inp = sprintf('%02d.jpg', K);
I = imread( fullfile(projectdir, inp) );
figure, imshow(I);
class = classify(convnet, I);
t = sprintf('file %s classified as %s', inp, string(class));
title(t);
end

2 Comments

Cannot find files or folders matching: 'D:\Fruit'.,是因為他跟我的總檔名跟Fruit不一樣才找不到嗎
I cannot tell where the directory of training files is, but I can see that your test files are in your current directory, which appears to be your MATLAB Drive directory.
projectdir = 'D:\Fruit';
testfiledir = '.';
if ~isdir(projectdir)
error('Cannot find training directory "%s"', projectdir)
end
layers=[
imageInputLayer([227 227 3],"Name","imageinput")
convolution2dLayer([3 3],32,"Name","conv_4","Padding","same")
reluLayer("Name","relu_4")
maxPooling2dLayer([5 5],"Name","maxpool","Padding","same")
convolution2dLayer([3 3],32,"Name","conv_6","Padding","same")
reluLayer("Name","relu_6")
fullyConnectedLayer(5,"Name","br")
softmaxLayer("Name","brian076269")
classificationLayer("Name","classoutput")];
plot(layerGraph(layers));
exts = { '.jpg' };
imds = imageDatastore( projectdir, 'IncludeSubfolders' , true, 'LabelSource' , 'foldernames' , 'FileExtensions' , exts);
options=trainingOptions('adam''Maxepoches',4,'intiaLearnRate',0.0001);
convnet=trainNetwork(imds,layers,options);
for K = 1 : 5
inp = sprintf('%02d.jpg', K);
try
fullinp = fullfile(testfiledir, inp);
if ~exist(fullinp)
fprintf('2, 'Could not find input file "%s"\n', fullinp);
continue
end
I = imread( fullinp );
figure, imshow(I);
class = classify(convnet, I);
t = sprintf('file %s classified as %s', inp, string(class));
title(t);
catch ME
fprintf(2, 'problem trying to process file "%s"\n', fullinp);
end
end

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!