How to save neural network

조회 수: 7 (최근 30일)
Parth Moradiya
Parth Moradiya 2012년 11월 14일
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.

채택된 답변

Greg Heath
Greg Heath 2012년 11월 14일
편집: Greg Heath 2013년 4월 7일
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
Greg Heath
Greg Heath 2013년 4월 7일
Close. I had defined a similar function which wasn't quite as general: max(abs(x)) instead of max(abs(x(:))

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Deep Learning Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by