MATLAB Answers

0

App designer error classify

Asked by Pablo Salaverria on 10 Jun 2019
Latest activity Commented on by Pablo Salaverria on 11 Jun 2019
Dear all,
while creating an app using app designer I am not able to compeltelly deploy my trainned CNN. My main issue is wiht the function classify which should be valid with:
[YPred]= classify(app.net,app.imds1);
Where app.net is the trainned CNN, app.imds1 is the imageDatastore where all the images that I want to classify are stored.
The error message that I got is:
Error using classify (line 123)
Requires at least three arguments.
Meaning that the function classify is using a 2nd options instead of the one that I want it to use. Is there a way to make it work? Could it be that I did not completelly unistall Matlab 2018b from my computer? I have 2019a running but it never occurred this error before...
The full code is the following one:
classdef ICapp < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
DistanceEvolution matlab.ui.control.UIAxes
UITable matlab.ui.control.Table
Load matlab.ui.control.StateButton
Predict matlab.ui.control.StateButton
FrameNSpinnerLabel matlab.ui.control.Label
FrameNSpinner matlab.ui.control.Spinner
Save matlab.ui.control.Button
DistanceextrantionappLabel matlab.ui.control.Label
Image matlab.ui.control.Image
Image_2 matlab.ui.control.Image
PLOT matlab.ui.control.UIAxes
DoneLampLabel matlab.ui.control.Label
DoneLamp matlab.ui.control.Lamp
DoneLamp_2Label matlab.ui.control.Label
DoneLamp_2 matlab.ui.control.Lamp
DoneLamp_3Label matlab.ui.control.Label
DoneLamp_3 matlab.ui.control.Lamp
end
properties (Access = private)
imds0;
table;
imds1;
NFrame;
frames;
Name;
net;
predictY;
Info;
% Description
end
methods (Access = private)
end
% Callbacks that handle component events
methods (Access = private)
% Code that executes after component creation
function startupFcn(app, NET, example)
app.net=load("net.mat");
example=imageDatastore('example.png');
img = readimage(example,1);
imshow(img,'Parent',app.PLOT);
app.table = readtable('Example.xlsx');
app.UITable.Data=app.table;
end
% Value changed function: Load
function LoadValueChanged(app, event)
DataLocation=uigetdir('Location of the data');
app.imds0 = imageDatastore(fullfile(DataLocation),'FileExtensions','.png');
app.imds1 = augmentedImageDatastore([224 224],app.imds0 );
% N° of frames
S=size(app.imds0.Files);
app.frames=S(1,1);
app.NFrame = 1:1:S(1,1);app.NFrame=app.NFrame';
app.NFrame;
app.table.FrameN_(1:S(1,1))=app.NFrame;
% Names of those frames
app.Name=app.imds0.Files;
app.table.ImageName(1:S(1,1))=app.Name;
% Load all the data
app.UITable.Data=app.table;
% Switch on lamp
app.DoneLamp.Color='g';
end
% Value changing function: FrameNSpinner
function FrameNSpinnerValueChanging(app, event)
end
% Value changed function: FrameNSpinner
function FrameNSpinnerValueChanged(app, event)
FrameN = app.FrameNSpinner.Value;
images1=readimage(app.imds0,FrameN);
imshow(images1,'Parent',app.PLOT)
end
% Value changed function: Predict
function PredictValueChanged(app, event)
app.net
app.imds1
group=18;
[YPred]= classify(app.net,app.imds1);
s=string(YPred);
app.predictY=double(s);
app.table.Distance(1:app.frames)=app.predictY;
app.DoneLamp_2.Color='g';
end
end
% Component initialization
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure and hide until all components are created
app.UIFigure = uifigure('Visible', 'off');
app.UIFigure.Position = [100 100 1170 742];
app.UIFigure.Name = 'UI Figure';
% Create DistanceEvolution
app.DistanceEvolution = uiaxes(app.UIFigure);
title(app.DistanceEvolution, 'Distance evolution ')
xlabel(app.DistanceEvolution, 'Frame N°')
ylabel(app.DistanceEvolution, 'Distance(pixels)')
app.DistanceEvolution.Position = [561 40 570 321];
% Create UITable
app.UITable = uitable(app.UIFigure);
app.UITable.ColumnName = {'Frame N°'; 'ImageName'; 'Distance'};
app.UITable.ColumnWidth = {'auto'};
app.UITable.RowName = {};
app.UITable.Position = [17 73 528 274];
% Create Load
app.Load = uibutton(app.UIFigure, 'state');
app.Load.ValueChangedFcn = createCallbackFcn(app, @LoadValueChanged, true);
app.Load.Text = 'LOAD';
app.Load.FontWeight = 'bold';
app.Load.Position = [91 611 100 22];
% Create Predict
app.Predict = uibutton(app.UIFigure, 'state');
app.Predict.ValueChangedFcn = createCallbackFcn(app, @PredictValueChanged, true);
app.Predict.Text = {'PREDICT'; ''};
app.Predict.FontWeight = 'bold';
app.Predict.Position = [91 581 100 22];
% Create FrameNSpinnerLabel
app.FrameNSpinnerLabel = uilabel(app.UIFigure);
app.FrameNSpinnerLabel.HorizontalAlignment = 'center';
app.FrameNSpinnerLabel.Position = [699 404 57 22];
app.FrameNSpinnerLabel.Text = 'Frame N°';
% Create FrameNSpinner
app.FrameNSpinner = uispinner(app.UIFigure);
app.FrameNSpinner.ValueChangingFcn = createCallbackFcn(app, @FrameNSpinnerValueChanging, true);
app.FrameNSpinner.ValueChangedFcn = createCallbackFcn(app, @FrameNSpinnerValueChanged, true);
app.FrameNSpinner.HorizontalAlignment = 'center';
app.FrameNSpinner.Position = [755 404 45 22];
app.FrameNSpinner.Value = 1;
% Create Save
app.Save = uibutton(app.UIFigure, 'push');
app.Save.FontWeight = 'bold';
app.Save.Position = [91 551 100 22];
app.Save.Text = {'SAVE'; ''};
% Create DistanceextrantionappLabel
app.DistanceextrantionappLabel = uilabel(app.UIFigure);
app.DistanceextrantionappLabel.FontSize = 40;
app.DistanceextrantionappLabel.Position = [111 685 434 48];
app.DistanceextrantionappLabel.Text = 'Distance extrantion app';
% Create Image
app.Image = uiimage(app.UIFigure);
app.Image.Position = [17 653 86 80];
app.Image.ImageSource = '0.jpg';
% Create Image_2
app.Image_2 = uiimage(app.UIFigure);
app.Image_2.Position = [544 653 86 80];
app.Image_2.ImageSource = 'ijm_logo.jpg';
% Create PLOT
app.PLOT = uiaxes(app.UIFigure);
title(app.PLOT, 'Preview')
xlabel(app.PLOT, '')
ylabel(app.PLOT, '')
app.PLOT.FontSize = 14;
app.PLOT.Position = [799 360 332 344];
% Create DoneLampLabel
app.DoneLampLabel = uilabel(app.UIFigure);
app.DoneLampLabel.HorizontalAlignment = 'right';
app.DoneLampLabel.Position = [209 611 34 22];
app.DoneLampLabel.Text = 'Done';
% Create DoneLamp
app.DoneLamp = uilamp(app.UIFigure);
app.DoneLamp.Position = [258 611 20 20];
app.DoneLamp.Color = [1 0 0];
% Create DoneLamp_2Label
app.DoneLamp_2Label = uilabel(app.UIFigure);
app.DoneLamp_2Label.HorizontalAlignment = 'right';
app.DoneLamp_2Label.Position = [209 581 34 22];
app.DoneLamp_2Label.Text = 'Done';
% Create DoneLamp_2
app.DoneLamp_2 = uilamp(app.UIFigure);
app.DoneLamp_2.Position = [258 581 20 20];
app.DoneLamp_2.Color = [1 0 0];
% Create DoneLamp_3Label
app.DoneLamp_3Label = uilabel(app.UIFigure);
app.DoneLamp_3Label.HorizontalAlignment = 'right';
app.DoneLamp_3Label.Position = [209 551 34 22];
app.DoneLamp_3Label.Text = 'Done';
% Create DoneLamp_3
app.DoneLamp_3 = uilamp(app.UIFigure);
app.DoneLamp_3.Position = [258 551 20 20];
app.DoneLamp_3.Color = [1 0 0];
% Show the figure after all components are created
app.UIFigure.Visible = 'on';
end
end
% App creation and deletion
methods (Access = public)
% Construct app
function app = ICapp(varargin)
% Create UIFigure and components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
% Execute the startup function
runStartupFcn(app, @(app)startupFcn(app, varargin{:}))
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.UIFigure)
end
end
end

  0 Comments

Sign in to comment.

1 Answer

Answer by Kojiro Saito on 11 Jun 2019
 Accepted Answer

Your classify function is treated as that of Statistics and Machine Learning Toolbox in the compiled application. In order to force compiled application to use CNN classify, there are two ways.
(1) Use SeriesNetwork.loadobj
function startupFcn(app, NET, example)
app.net = load("net.mat");
app.net = SeriesNetwork.loadobj(app.net.net);
% ... %
end
(2) User function progma (%#) in the first line of startupFcn
function startupFcn(app, NET, example)
%#function SeriesNetwork
app.net = load("net.mat");
app.net = app.net.net;
% ... %
end
Hope this helps..

  1 Comment

It worked!!!! Thank you very much!!!

Sign in to comment.