Saving Label output using for loop
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Benjamin Currie
el 21 de Mzo. de 2021
Respondida: Srivardhan Gadila
el 23 de Mzo. de 2021
image_folder = cd;
filenames = dir(fullfile(image_folder, '*.jpg'));
total_images = numel(filenames);
col = cell(1, total_images);
for n = 1:total_images
net = googlenet;
inputSize = net.Layers(1).InputSize;
classNames = net.Layers(end).ClassNames;
numClasses = numel(classNames);
f = fullfile(image_folder, filenames(n).name);
our_images = imread(f);
I = imresize(our_images,inputSize(1:2));
[label,scores] = classify(net,I);
label
col{1,n} = sprintf(label, n);
end
I am using the following code, what it does is run each image and assign a label to it. What I am trying to do is save each label in the same array also to save me writing it all out on excel as they are a lot of photos. there is a problem with the final line as saying label is not suitable. When i type 'label' it just saves the word label in each array section. Anyone have any idea how to save each outputted label? An example of the output labels for one of the images = "Fridge". When i dont add the final line it just outputs all the labels in the command window. Thanks
0 comentarios
Respuesta aceptada
Srivardhan Gadila
el 23 de Mzo. de 2021
image_folder = cd;
filenames = dir(fullfile(image_folder, '*.jpg'));
net = googlenet;
inputSize = net.Layers(1).InputSize;
classNames = net.Layers(end).ClassNames;
numClasses = numel(classNames);
total_images = numel(filenames);
labels = categorical.empty(total_images,0);
for n = 1:total_images
f = fullfile(image_folder, filenames(n).name);
our_images = imread(f);
I = imresize(our_images,inputSize(1:2));
[label,scores] = classify(net,I);
label
labels(n,1) = label;
end
labelsStr = string(labels)
Alternatively you can make use of imageDatastore, augmentedImageDatastore and avoid the for loop and use YPred = classify(net,ds) function to get the predictions directly using the datastore.
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Data Distribution Plots 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!