Labeling images using own trained classifier

Illustration
Andrea-magni - 2021-05-31T12:27:55+00:00
Question: 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()?

Expert Answer

Profile picture of Neeta Dsouza Neeta Dsouza answered . 2025-11-20

try 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')

 


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!