Borrar filtros
Borrar filtros

add pretrained LSTM regression model to app designer

3 visualizaciones (últimos 30 días)
kouadri saber
kouadri saber el 14 de En. de 2022
Respondida: prabhat kumar sharma el 3 de Abr. de 2024
classdef app1 < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
Gauge matlab.ui.control.Gauge
GaugeLabel matlab.ui.control.Label
ShowdatagraphButton matlab.ui.control.Button
TDSSpinner matlab.ui.control.Spinner
TDSSpinnerLabel matlab.ui.control.Label
THSpinner matlab.ui.control.Spinner
THSpinnerLabel matlab.ui.control.Label
predictButton matlab.ui.control.Button
UIAxes matlab.ui.control.UIAxes
end
properties (Access = private)
net;
Y_predict;
end
methods (Access = private)
function startupFcn(app)
app.net = load("C:\Users\SABER\AppData\TESTapp\net.mat");
app.net = app.net.net;
end
end
% Callbacks that handle component events
methods (Access = private)
% Button pushed function: predictButton
function predictButtonPushed(app, event)
%assignin('base','TDS', app.TDSSpinner.Value);
%assignin('base','TH', app.THSpinner.Value);
%new = [num2str(app.TDSSpinner.Value); num2str(app.THSpinner.Value)];
%assignin('base','new', new);
app.Y_predict = predict(app.net,input);
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 643 449];
app.UIFigure.Name = 'UI Figure';
% Create UIAxes
app.UIAxes = uiaxes(app.UIFigure);
title(app.UIAxes, 'DATA View')
xlabel(app.UIAxes, 'X')
ylabel(app.UIAxes, 'Y')
app.UIAxes.Position = [1 183 640 241];
% Create predictButton
app.predictButton = uibutton(app.UIFigure, 'push');
app.predictButton.ButtonPushedFcn = createCallbackFcn(app, @predictButtonPushed, true);
app.predictButton.Position = [254 51 100 22];
app.predictButton.Text = 'predict';
% Create THSpinnerLabel
app.THSpinnerLabel = uilabel(app.UIFigure);
app.THSpinnerLabel.HorizontalAlignment = 'right';
app.THSpinnerLabel.Position = [214 119 25 22];
app.THSpinnerLabel.Text = 'TH';
% Create THSpinner
app.THSpinner = uispinner(app.UIFigure);
app.THSpinner.Limits = [0 Inf];
app.THSpinner.HorizontalAlignment = 'center';
app.THSpinner.Position = [254 119 100 22];
% Create TDSSpinnerLabel
app.TDSSpinnerLabel = uilabel(app.UIFigure);
app.TDSSpinnerLabel.HorizontalAlignment = 'right';
app.TDSSpinnerLabel.Position = [212 82 29 22];
app.TDSSpinnerLabel.Text = 'TDS';
% Create TDSSpinner
app.TDSSpinner = uispinner(app.UIFigure);
app.TDSSpinner.Limits = [0 Inf];
app.TDSSpinner.HorizontalAlignment = 'center';
app.TDSSpinner.Position = [256 82 100 22];
% Create ShowdatagraphButton
app.ShowdatagraphButton = uibutton(app.UIFigure, 'push');
app.ShowdatagraphButton.Position = [47 162 106 22];
app.ShowdatagraphButton.Text = 'Show data graph';
% Create GaugeLabel
app.GaugeLabel = uilabel(app.UIFigure);
app.GaugeLabel.HorizontalAlignment = 'center';
app.GaugeLabel.Position = [461 6 42 22];
app.GaugeLabel.Text = 'Gauge';
% Create Gauge
app.Gauge = uigauge(app.UIFigure, 'circular');
app.Gauge.Limits = [0 300];
app.Gauge.ScaleColors = [0 1 0;1 1 0;1 0.4118 0.1608;1 0 0];
app.Gauge.ScaleColorLimits = [0 50;50 100;100 150;150 300];
app.Gauge.Position = [421 43 120 120];
% 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 = app1
% Create UIFigure and components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
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

Respuestas (1)

prabhat kumar sharma
prabhat kumar sharma el 3 de Abr. de 2024
Hi Kouadri,
I assume that you are facing issue with using a pretrained LSTM network inside the app designer based application.
So for Integrating a pre-trained LSTM regression model into a MATLAB App Designer app involves loading the model within the app and using it to make predictions based on user input. The code snippet you've provided an idea about the structure of an App Designer app class. To complete the LSTM integration, You can focus on two main aspects:
1. Loading the Pre-trained Model
2. Making Predictions
You can refer the below code snippet for understanding the basic workflow and outline.
classdef app1 < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
Gauge matlab.ui.control.Gauge
GaugeLabel matlab.ui.control.Label
ShowdatagraphButton matlab.ui.control.Button
TDSSpinner matlab.ui.control.Spinner
TDSSpinnerLabel matlab.ui.control.Label
THSpinner matlab.ui.control.Spinner
THSpinnerLabel matlab.ui.control.Label
predictButton matlab.ui.control.Button
UIAxes matlab.ui.control.UIAxes
end
properties (Access = private)
net; % The pre-trained LSTM network
Y_predict; % The prediction result
end
methods (Access = private)
function startupFcn(app)
% Here you can load the pre-trained LSTM network
modelStruct = load("C:\Users\SABER\AppData\TESTapp\net.mat");
app.net = modelStruct.net;
end
end
% Callbacks that handle component events
methods (Access = private)
% Button pushed function: predictButton
function predictButtonPushed(app, event)
% Gather input values
TDS = app.TDSSpinner.Value;
TH = app.THSpinner.Value;
% Assuming your model expects a 1x2 input array
% You might need to adjust preprocessing based on your model's requirements
input = [TDS, TH];
% Reshape input if necessary for your LSTM model
% For example, LSTM might expect input as [features, timesteps, samples]
% input = reshape(input, [1, 1, 2]); % Adjust based on your model's input shape
% Predict using the pre-trained LSTM network
app.Y_predict = predict(app.net, input);
% Update UI elements based on the prediction
% For example, updating the Gauge value
% Ensure to adjust the value to fit within the Gauge limits
app.Gauge.Value = app.Y_predict;
end
end
% Component initialization and other app methods...
% App creation, component creation, and app deletion methods remain unchanged
end
I hope it helps!

Categorías

Más información sobre Develop uifigure-Based Apps en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by