我不知道哪裡打錯cannot find files or folders matching
Show older comments
imds=imageDatastore('D:/fruit','IncludeSubfolders',true,'LabelSource','foldernames
我有5張水果圖片存在d槽,總檔名就叫fruit,可是哪裡錯了?
1 Comment
YONG HAO WANG
on 15 Oct 2022
Moved: Walter Roberson
on 15 Oct 2022
Accepted Answer
More Answers (2)
Hi,
Please refer to the linked documentation for more info about the syntax on "imageDataStore":
7 Comments
YONG HAO WANG
on 14 Oct 2022
Walter Roberson
on 14 Oct 2022
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.)
YONG HAO WANG
on 14 Oct 2022
Walter Roberson
on 14 Oct 2022
Please show the output of
ls('D:\')
YONG HAO WANG
on 14 Oct 2022
YONG HAO WANG
on 14 Oct 2022
Walter Roberson
on 14 Oct 2022
Edited: Walter Roberson
on 15 Oct 2022
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
Walter Roberson
on 15 Oct 2022
Moved: Walter Roberson
on 15 Oct 2022
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
YONG HAO WANG
on 15 Oct 2022
Edited: YONG HAO WANG
on 15 Oct 2022
Walter Roberson
on 15 Oct 2022
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
Categories
Find more on Vehicle Network Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


