Labeling images using own trained classifier

Andrea-magni · May 31, 2021 · 2.2K views
Question
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 PhD Expert
Answered Aug 26, 2026

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

 

100% Run Guarantee 3-Hour Fast-Track Delivery

Need a Custom Version or Complete Simulation for This Problem?

Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.

Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!