Labeling images using own trained classifier

Hi, I have created a classifier using CNN (vgg16) for the feature extraction and KNN to classify using a dataset made of 1000 images with accuracy of 96% for train and 94% for test. The question is: How can I use my classifier to label one given image? Say I have one image on an apple and I want my classifier to recognize the apple, how can I know the corresponding label of the image (in this case apple)?
What kind of function should I use? predict()?

 Respuesta aceptada

Image Analyst
Image Analyst el 25 de Ag. de 2018
Yes. You can do like this:
newImage = imread(fullfile(rootFolder, 'airplanes', 'image_0690.jpg'));
% Create augmentedImageDatastore to automatically resize the image when
% image features are extracted using activations.
ds = augmentedImageDatastore(imageSize, newImage, 'ColorPreprocessing', 'gray2rgb');
% Extract image features using the CNN
imageFeatures = activations(net, ds, featureLayer, 'OutputAs', 'columns');
% Make a prediction using the classifier
label = predict(classifier, imageFeatures, 'ObservationsIn', 'columns')
See this link and it will walk you through it step by step.

4 comentarios

Andrea Magni
Andrea Magni el 25 de Ag. de 2018
It gives me this error: Error using ClassificationKNN/predict Too many input arguments.
Image Analyst
Image Analyst el 26 de Ag. de 2018
If you're having trouble running one of the MATLAB scripts in their documentation, you can call them on the phone and they'll work with you to figure out what the problem is.
Patricia-Carmen Tibre
Patricia-Carmen Tibre el 8 de Mayo de 2020
Editada: Patricia-Carmen Tibre el 8 de Mayo de 2020
Hello Mr. Image Analyst!
I kinda have the same problem of image labeling. I have to make the classification using SVM and I used CNN to extract features from images. I also have to random the features extracted ( by columns because 1 column = 1 image features ) and when i do that the classification is wrong. Can you give me some tips? I`m thinking that maybe i should have label the columns not the images but maybe I`m wrong. Thank you!
So you used CNN (or I guess RCNN) to collect a bunch of estimated feature values (for example x, y, meanGrayLevel, standard deviation) from a set of images, and now you want to randomize that feature matrix. I guess the feature matrix has image numbers going down the rows, and each feature is in its own column, right? And did you also do a classification CNN (the usual, standard, simplest kind) to get an estimated class for each image? And the predicted class is one column of your feature matrix. So your feature matrix is like
image# predictedClass x y meanGrayLevel StdDev
image1 1 5 8 200 2.5
image2 2 9 3 120 4.9
image3 1 4 6 189 8.4
or something like that?
You can use the randsample() function to extract a subset of your matrix.
Or you can get a random ordering yourself using the randperm() function to scramble the order
sortOrder = randperm(size(featureMatrix, 1));
featureMatrix = featureMatrix(sortOrder, :);

Iniciar sesión para comentar.

Más respuestas (0)

Preguntada:

el 25 de Ag. de 2018

Comentada:

el 7 de Dic. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by