How to save neural network

7 Ansichten (letzte 30 Tage)
Parth Moradiya
Parth Moradiya am 14 Nov. 2012
I have used neural network to the datasets and now if i trained network one time and now i want to apply this network to different datasets then how i can apply? I want to do this because i want to compare how efficient the transferability? I am eager to find solution.

Akzeptierte Antwort

Greg Heath
Greg Heath am 14 Nov. 2012
Bearbeitet: Greg Heath am 7 Apr. 2013
clear all, close all, clc;
[x,t] = simplefit_dataset;
[I N ] = size(x)
[O N ] = size(t)
xtrn = x(1:2:N);
ttrn = t(1:2:N);
MSEtrn00 = var(ttrn',1) % Reference MSEtrn
xval = []; % No val data for Early Stopping
tval = [];
xtst = x(2:2:N); % For post training testing
ttst = t(2:2:N);
MSEtst00 = var(ttst',1) % Reference MSEtst
H = 4 % Minimized by trial & error
net = fitnet(H);
net.divideFcn = ''; % No automatic data division
net.trainParam.goal = 0.01*MSEtrn00; % Want training R^2 >= 0.99
[net tr Ytrn Etrn] = train(net,xtrn,ttrn);
ytrn = net(xtrn);
etrn = ttrn-ytrn;
MSEtrn =mse(etrn)
check1 = max(abs(ytrn - Ytrn))
check2 = max(abs(etrn - Etrn))
check3 = max(abs(MSEtrn - tr.perf(end)))
NMSEtrn = MSEtrn/MSEtrn00 % Normalized
R2trn = 1-NMSEtrn % R^2
% Save for use with other data
net01 = net;
save net01 % Save
whos net net01 % Both in workspace
pause(5)
clear net net01 % Cleared from workspace
whos % Proof
%Retrieve and use
load net01
ytst = net01(xtst);
MSEtst = mse(ttst-ytst)
R2tst = 1-MSEtst/MSEtst00
Hope this helps
Thank you for formally accepting my answer
Greg
  3 Kommentare
Greg Heath
Greg Heath am 7 Apr. 2013
Close. I had defined a similar function which wasn't quite as general: max(abs(x)) instead of max(abs(x(:))

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

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

Community Treasure Hunt

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

Start Hunting!

Translated by