Error using imread>get_full_filename

12 visualizaciones (últimos 30 días)
Ali Nawaz
Ali Nawaz el 4 de Oct. de 2020
Comentada: Image Analyst el 5 de Oct. de 2020
I'm running the below code for my algorithm. Everything is working fine but imread() is giving an error in a loop. If I run the command separately it gives the output but in the loop it's showing an error. Could you please help me out?
Trainingpath = 'Destination Foler path';
imagesets = imageDatastore(Trainingpath,'IncludeSubfolders',true,'LabelSource',...
'foldernames');
[traindata,validation] = splitEachLabel(imagesets,0.50,'randomize');
extracted_features = bagOfFeatures(traindata);
Sclassifier = trainImageCategoryClassifier(traindata,extracted_features);
ConfusMatrix = evaluate(Sclassifier,validation);
mean(diag(ConfusMatrix));
imagename = uigetfile({'*.jpg;*.tif;*.png;*.gif','All Image Files';...
'*.*','All Files' });
image = imread(imagename); %?????????????????????
[Label, score] = predict(Sclassifier,image);
prediction = Sclassifier.Labels(Label);
%fprintf(imagename, prediction);
imagename, prediction

Respuesta aceptada

Image Analyst
Image Analyst el 4 de Oct. de 2020
image is the name of a built-in function. Do NOT use it as the name of your variable. Try this:
% Have user browse for a file, from a specified "starting folder."
% For convenience in browsing, set a starting folder from which to browse.
startingFolder = Trainingpath; % or 'C:\wherever';
if ~isfolder(startingFolder)
% If that folder doesn't exist, just start in the current folder.
startingFolder = pwd;
end
% Get the name of the file that the user wants to use.
defaultFileName = fullfile(startingFolder, '*.*');
[baseFileName, folder] = uigetfile(defaultFileName, 'Select a file');
if baseFileName == 0
% User clicked the Cancel button.
break; % Exit loop
end
fullFileName = fullfile(folder, baseFileName);
fprintf('Reading in "%s"\n', fullFileName);
rgbImage = imread(fullFileName);
fprintf('Predicting "%s"\n', fullFileName);
[Label, score] = predict(Sclassifier, rgbImage);
  2 comentarios
Ali Nawaz
Ali Nawaz el 5 de Oct. de 2020
I'm really thankful to you for this prompt solution. I've implemented these steps and it's working perfectly fine. One more thing could you please explain that : " How I can confirm the selected image i.e. the image which user selected from the dataset gives me the right answer".
From label and score, Can I predict the selected image is the right one. The algorithm is detecting the right image or not. I'm really confused.
Image Analyst
Image Analyst el 5 de Oct. de 2020
For any training situation, you have 3 sets of images:
  1. training set that you use to train the model. The training set has known, predetermined classes.
  2. validation that you use to test the model you trained. The validation set has known, predetermined classes.
  3. test set. The test set is your actual data. You don't know the answer for these images, and are hoping your algorithm will tell you accurately what the answer is.
Of course for 1 and 2, you KNOW whether your algorithm predicted the right answer or not. For 3 (test set) you don't know for certain, but you have a belief that it got it right at a percentage that you get from running the validation set through your algorithm.
I'm not sure which set your "selected image" falls into, 2 or 3. But the answer is as I described in the last paragraph.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Communications Toolbox en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by