How to load and predict using my trained deep neural network in MATLAB GUI window?

9 visualizzazioni (ultimi 30 giorni)
hi!
I have a trained deep neural network using my own dataset. How do i load my trained network in the GUI and predict the output using any random image. I have developed GUI using App Desinger. Please help
Tried to load network using different ways:
One way-
trained_net_vars = load('E:\Subject\newtrain_05_12.mat');
handles.neural_net = trained_net_vars.net;
guidata(hObject, handles)
Second way -
% [f, p, i]=uigetfile('*.mat');
% f_name=fullfile(p,f);
% a=load(f_name);
% A_cell = struct2cell(a);

Risposte (1)

Sanjana
Sanjana il 27 Mar 2023
Hi,
I understand that you're facing difficulties in creating a GUI window to load a pretrained model and perform predictions on random images, and then display the prediction. Here is a possible solution:
Firstly, you can add a “button” and an “Image” component to the canvas in the App Designer. Then, write a “callback” function for the “button” component as follows:
function LoadImageButtonPushed(app, event)
net = load('modelName.mat');
[filename, pathname] = uigetfile({'*.jpg;*.png;*.bmp', 'Image files'}, 'Select an image');
filepath = fullfile(pathname, filename);
app.Image.ImageSource = filepath;
img = imread(filepath);
prediction = predict(net,img);
app.OutputLabel.Text = prediction;
end
Hope this helps!
  1 Commento
shazia
shazia il 11 Set 2023
hello , if i want to pass my test data (not image) and the genrated trained net to GUI for prediction, how i would do that could you plz elobrate.
thank you

Accedi per commentare.

Categorie

Scopri di più su Image Data Workflows in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by