how to fix the following error-

I'm using matlab 2015b version. i ve constructed a Multilayer perceptron model to predict the gender of a person. While testing the model i get the following error-Systems of struct class cannot be used with the "predict" command. Convert the system to an identified model first, such as by using the "idss" command. Error in maintest (line 55) label = predict(model,S); how to fix this error..

14 Kommentare

Walter Roberson
Walter Roberson am 19 Okt. 2017
How many gender classes did you code for? A lot of people get the model badly wrong by failing to code at least 7 at absolute minimum.
Annie micheal
Annie micheal am 20 Okt. 2017
Two classes(male and female)
Walter Roberson
Walter Roberson am 20 Okt. 2017
Two-class gender determination is like rolling a 6 sided dice, assigning Male if you get a 1, assigning Female if you get a 6, and returning FAIL for the other 4 cases. And sometimes the form of that FAIL is that the program crashes.
Anyhow, we can refer you to https://www.mathworks.com/help/matlab/matlab_prog/debugging-process-and-features.html; if you post the code then someone might notice something more specific.
Annie micheal
Annie micheal am 20 Okt. 2017
Bearbeitet: Torsten am 20 Okt. 2017
clear all;
clc;
modelFile = 'model_frontal.mat';
[fname,pname] = uigetfile('*.*','Select the input image file');
filename = sprintf('%s%s',pname,fname);
img1=imread(filename);
load(modelFile, 'npdModel');
rects = DetectFace(npdModel, img1);
numFaces = length(rects);
%fprintf('%d faces detected.\n', numFaces);
if numFaces > 0
border = round(size(img1,2) / 300);
if border < 2, border = 2; end
for j = 1 : numFaces
I = DrawRectangle(img1, rects(j).col, rects(j).row, rects(j).width, rects(j).height, [0 255 0], border);
cropI = imcrop(I,[rects(j).col, rects(j).row, rects(j).width, rects(j).height]);
end
end
sexs=zeros(size(rects, 1),1);
n=size(rects, 1);
text_str = cell(n,1);
position = zeros(n,2);
for i=1:n
text_str{i} = ['male '];
end
for i = 1:n
xs = rects(j).col;
xe = xs + rects(j).width;
ys = rects(j).row;
ye = ys + rects(j).height;
gray=rgb2gray(I(ys:ye, xs:xe, :));
gray2=imresize(gray,[256 256]);
% load radius1
class = 0;
value=WLD(gray2)
O = value;
%img= imresize(img,[256 256]);
%roi = [rects(j).col; rects(j).row; rects(j).width; rects(j).height];
roi= [1; rects(j).height;1;rects(j).width;];
%Q =mean(Q2);
S=[O]
%#function model
modelFile = 'MainClassifier.mat';
load(modelFile, 'model');
sys=idss(model);
end
%sys=idss(model);
label = predict(sys,S);
position(i,1)=xs;
position(i,2)=ye;
if label==1
text_str='male';
else
text_str='female';
end
shapeInserter = vision.ShapeInserter('BorderColor','Custom','CustomBorderColor',[255 50 50]);
I = step(shapeInserter, img1,int8([rects(j).col, rects(j).row, rects(j).width, rects(j).height]));
A = insertText(I, position, text_str,'FontSize',18,'BoxOpacity',0.4,'TextColor','white');
%RGB = insertText(I,position,text_str,'FontSize',18,'BoxColor',box_color,'BoxOpacity',0.4,'TextColor','white');
figure;
imshow(A);
Annie micheal
Annie micheal am 25 Okt. 2017
i've posted my code above.. i'm getting the following error Error using checkMatrix (line 17) State-space matrix "d" must be double.
Error in idss (line 234) D = checkMatrix(varargin{1},'d');
Error in maintest (line 52) sys=idss(model);
pls can u help me to fix this error
Which MATLAB version are you using, and what shows up for
class(model)
?
if label==1
text_str='male';
else
text_str='female';
end
I have friends who are filing human rights complaints over that kind of logic, and based upon precedent are considered likely to win. not "male" is not the same thing as "female" !
i'm using matlab 2015b version. model has the following structure model =
input: 2*96 double
target: [1;2]
learning_rate:0.1000
momentum: 0.1000
weights: 1*2 cell
biases: 1*2 cell
lastdelta:1*2 cell
Walter Roberson
Walter Roberson am 25 Okt. 2017
In your MainClassifier.mat file, how did you create the 'model' variable that is showing up as a struct? And which MATLAB version was used to create that .mat ? (If you happened to have created an object in a later version of MATLAB and tried to load it in an earlier version, it can show up as a struct.)
Annie micheal
Annie micheal am 25 Okt. 2017
i've created the model variable using multilayer perceptron(MLP).. it is a MLP model. only Matlab 2015b version was used to create the model..
Walter Roberson
Walter Roberson am 25 Okt. 2017
Which function did you call, from which File Exchange or third-party contribution?
Annie micheal
Annie micheal am 25 Okt. 2017
Bearbeitet: Walter Roberson am 25 Okt. 2017
from thrid- party contribution.. i ve posted the code
function [model cc output] = train_mlp(input, target, hidden, iterations, learning_rate, momentum)
% this is the function that handles all the looping and running of the
% neural network, it initializes the network based on the number of
% hidden layers, and presents every item in the input over and over,
% $iterations$ times.
% hidden is the only complicated variables. Like weka, it accepts a
% list of values (as a row vector), and interprets it as the number of
% neurons in each hidden layer, so [2 2 2] means there will be an input
% layer defined by the size of the input, three hidden layers, with 2
% neurons each, and the output layer, defined by the target. I think
% it's pretty good.
% initialize the output
model = [];
model.input=input;
model.target=target;
model.learning_rate = learning_rate;
model.momentum = momentum; % for some heavy ball action
% characterize the input and output
[ntrain nInLayer] = size(input);
[jnk nOutLayer] = size(target);
% keep track of how many neurons are in each layer
nNeurons = [nInLayer hidden nOutLayer];
nNeurons(nNeurons == 0) = []; % remove 0 layers, to allow putting a zero for no hidden layers
% there are one fewer sets of weights and biases as total layers
nTransitions = length(nNeurons)-1;
for i = 1:nTransitions % initialize the weights between layers, and the biases (past the first layer)
model.weights{i} = randn(nNeurons(i),nNeurons(i+1));
% the weight matrix has X rows, where X is the number of input
% neurons to the layer, and Y columns, where Y is the number of
% output neurons. multiplication of the input with the weight
% matrix transforms the dimensionality of the input to that of the
% output. Initialization is done here randomly.
model.biases{i} = randn(1,nNeurons(i+1));
%double(model.biases{i});
% biases are random as well
model.lastdelta{i} = 0;
end
for i = 1:iterations % repeat the whole training set over and over
order = randperm(ntrain); % randomize the presentations
for j = 1:ntrain
% update_mlp is where the training is actually done
model = update_mlp(model, input(order(j),:), target(order(j),:));
end
end
% test the performance on the training set after all is trained.
[output cc] = test_mlp(model, input, target);
save MainClassifier.mat model;
end
Walter Roberson
Walter Roberson am 25 Okt. 2017
predict() can be one of:
Computer Vision Toolbox:
Control System Toolbox:
Neural Network Toolbox:
Statistics and Machine Learning Toolbox:
SymBiology Toolbox:
System Identification Toolbox:
Text Analytics Toolbox:
Which of those were you intending that your predict() command invoke?
Annie micheal
Annie micheal am 26 Okt. 2017
Bearbeitet: Walter Roberson am 26 Okt. 2017
Walter Roberson
Walter Roberson am 26 Okt. 2017
Okay, that is progress.
The Neural Network predict() command requires either a
SeriesNetwork or a DAGNetwork (Directed acyclic graph)
When I examine articles about MLP, I find that they are a non-cascaded Feed Forward Network, such as one might create with feedforwardnet() . However, feedforwardnet() is used for function approximation and clustering, and predict() is not applicable to such networks. Considering your purpose, I wonder if you would be better off with a <https://www.mathworks.com/help/nnet/ref/patternnet.html patternnet() for pattern recognition? Those do not use predict() either though.
The predict() for SeriesNetwork deals with networks that look fairly different in structure that MLP would have -- although possibly you could use such a network, it looks much more complicated than you need to me.
Anyhow, you have the fundamental problem that the third-party MLP training routine that you are using does not create a network structure that is in the form expected by any of the Neural Network Toolbox functions. If we could narrow down your needs, then possibly we could extract information from the training you did and use it to build something that could be used with the Neural Network toolbox.
... but I suspect that what you are supposed to do with the training structure you created is to call a third party routine to use it with. Certainly that would be the case if you are using http://3options.net/brainannex/multilayer-perceptron-in-matlab-octave/

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Deep Learning Toolbox finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 19 Okt. 2017

Kommentiert:

am 26 Okt. 2017

Community Treasure Hunt

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

Start Hunting!

Translated by