Labeling images using own trained classifier

조회 수: 1 (최근 30일)
Andrea Magni
Andrea Magni 2018년 8월 25일
댓글: zoulikha 2022년 12월 7일
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()?

채택된 답변

Image Analyst
Image Analyst 2018년 8월 25일
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
Patricia-Carmen Tibre
Patricia-Carmen Tibre 2020년 5월 8일
편집: Patricia-Carmen Tibre 2020년 5월 8일
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!
Image Analyst
Image Analyst 2020년 5월 8일
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, :);

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Recognition, Object Detection, and Semantic Segmentation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by