App designer error classify
    6 views (last 30 days)
  
       Show older comments
    
    Pablo Salaverria
      
 on 10 Jun 2019
  
    
    
    
    
    Commented: Kojiro Saito
    
      
 on 11 Jun 2022
            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
Accepted Answer
  Kojiro Saito
    
      
 on 11 Jun 2019
        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..
39 Comments
  Fatin Nasuha Bt Asrol
 on 11 Jun 2022
				@Kojiro Saito Thank you for reply. I already tried change it according your coding imgRes = imresize (img, [244 244]); but I get the another error like this:

  Kojiro Saito
    
      
 on 11 Jun 2022
				I'm a bit confused.
Is Deep Learning Toolbox installed and you have a valid license?
Is your trained model (trainedNetwork_1) allows imageInputLayer?
Your question is not related to App Designer any more, so if the above does not work, I think it's better if you would post a question in MATLAB Answers as a new question.
More Answers (0)
See Also
Categories
				Find more on Matrix Indexing in Help Center and File Exchange
			
	Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!














