How to read a single image from a folder and then classify it with a trained neural network?

11 views (last 30 days)
I trained my network for skin tumor classification and then saved it. Now I want to test the accuracy for some new images. It works fine using imageDatastore but what I really want is to be able to browse in my computer for an image and classify it using the trained network. Is this possible?
Below I have attached the test code for a set of images.
load incercare.mat
imds= imageDatastore('E:/LICENTA/BD_Skin_Cancer_Screening/mini_data/test/', ...
'IncludeSubfolders', true, ...
'LabelSource', 'foldernames' );
[YPred,probs] = classify(netTransfer,imds);
accuracy = mean(YPred == imds.Labels)
for i=1:10
subplot(2,5,i)
I = readimage(imds,idx(i));
imshow(I)
label = YPred(idx(i));
title(string(label) + ", " + num2str(100*max(probs(idx(i),:)),3) + "%");
end
  1 Comment
Amit
Amit on 5 Jun 2021
Dear Malina,
Accoridng to me Backpropagation Feedforward neural network would be best suited for your purpose.
Please send me your 'incercare.mat' file by email on amit.kenjale@gmail.com, I will analyze this file for its variables and suggest you best suited approach to get your work done..

Sign in to comment.

Answers (1)

Prateek Rai
Prateek Rai on 16 Aug 2021
To my understanding, you trained the network for skin tumor classification and want to classify a single image using the trained network.
A possible workaround is:
  • Step 1: Read the image.
image = imread(xyz) % xyz is the location of the image in computer.
  • Step 2: You can use use the nework variable and feed the image as its argument to compute the network output.
classificationOutput = netTransfer(image);
You can also refer to Classify Patterns with a Neural Network MathWorks documentation page to find more on classification with a neural network.

Community Treasure Hunt

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

Start Hunting!