MATLAB Answers

When I add new image , I want to get "the result" of image in neural network pattern recognition. How can I do this according to codes added?

1 view (last 30 days)
Ali Zulfikaroglu
Ali Zulfikaroglu on 14 Feb 2021
Commented: Abhishek Gupta on 22 Feb 2021
I am studying about mammogram images to detect cancer on breast image. There are three situations benign, malign and normal.
I trained my neural netwok with 100 images and get result 95% . I will create user interface and will select an image and get the result of what is this image benign or malign or normal .
I mean my training is done and I want to see my neural network ability to detect result. I will upload a new image in user interface and want to see result of image benign or malign or normal . But I don't know which codes can I add in neural network?
Here is code neural pattern recognition created by matlab ownself. Which code should be added to detect new image (for example for 101 th image) ?
% Solve a Pattern Recognition Problem with a Neural Network
% Script generated by Neural Pattern Recognition app
% Created 07-Feb-2021 15:50:44
% This script assumes these variables are defined:
% x - input data.
% y - target data.
x = x;
t = y;
% Choose a Training Function
% For a list of all training functions type: help nntrain
% 'trainlm' is usually fastest.
% 'trainbr' takes longer but may be better for challenging problems.
% 'trainscg' uses less memory. Suitable in low memory situations.
trainFcn = 'trainscg'; % Scaled conjugate gradient backpropagation.
% Create a Pattern Recognition Network
hiddenLayerSize = 10;
net = patternnet(hiddenLayerSize, trainFcn);
% Setup Division of Data for Training, Validation, Testing
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;
% Train the Network
[net,tr] = train(net,x,t);
% Test the Network
y = net(x);
e = gsubtract(t,y);
performance = perform(net,t,y)
tind = vec2ind(t);
yind = vec2ind(y);
percentErrors = sum(tind ~= yind)/numel(tind);
% View the Network
% Plots
% Uncomment these lines to enable various plots.
%figure, plotperform(tr)
%figure, plottrainstate(tr)
%figure, ploterrhist(e)
%figure, plotconfusion(t,y)
%figure, plotroc(t,y)

Answers (1)

Abhishek Gupta
Abhishek Gupta on 17 Feb 2021
Edited: Abhishek Gupta on 17 Feb 2021
As per my understanding, you want to make predictions for new input using your trained network. You can do the same using the 'predict()' function in MATLAB: -
predictions = predict(trainedNetwork,newImages);
For more information, check out the documentation here: -
Abhishek Gupta
Abhishek Gupta on 22 Feb 2021
What error are you getting while using "predict()"? What is the dimension of 'a'? Note that "a" should be an N-by-numFeatures numeric array, where N is the number of observations and numFeatures is the number of features of the input data. I see N=1 in your case, so "a" should be of (1x88) dimension.
For more information, check out the "Input Arguments" section of the documentation: -

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!