how i can save the output of hidden layer of neural network
조회 수: 7 (최근 30일)
이전 댓글 표시
after i complete my program,i want to save the output,weight and bias of hidden layer of neural network, can any one help me to do this? thanks
댓글 수: 0
채택된 답변
Greg Heath
2013년 4월 15일
close all, clear all, clc, plt=0;
delete h.mat
delete LW.mat
delete b2.mat
delete tsettings.mat
[ x, t ] = simplefit_dataset;
net = fitnet;
rng(4151941)
[ net tr y0 ] = train( net, x, t);
plt=plt+1,figure(plt) % figure 1
hold on
plot(x,t,'b--','LineWidth',2)
plot(x,y0,'r.','LineWidth',2)
legend('TARGET','NN OUTPUT')
xlabel('INPUT')
ylabel('TARGETAND NN OUTPUT')
title('SIMPLEFIT DATASET')
%Create tsettings, h, LW, b2
[xn xsettings] = mapminmax(x);
[tn tsettings] = mapminmax(t); % SAVE tsettings
b1 = cell2mat(net.b(1))
IW = cell2mat(net.IW)
[ I N ] = size(xn)
B1 = b1*ones(1,N);
% B1 = repmat(b,1,N); % Alternate
h = tanh(B1+IW*xn); % SAVE h
LW = cell2mat(net.LW) % SAVE LW
b2 = cell2mat(net.b(2)) % SAVE b2
clc
whos h LW b2 tsettings
dir
% save FILENAME ... is the command form of the syntax
% for convenient saving from the command line. With
% command syntax, you do not need to enclose strings in
% single quotation marks. Separate inputs with spaces
% instead of commas. Do not use command syntax if
% inputs such as FILENAME are variables.
save h
save LW
save b2
save tsettings
dir
whos N h LW b2 tsettings
disp('BEFORE CLEARING SAVED HIDDEN VARIABLES')
disp('ENTER TO CONTINUE')
pause
dir
clear h LW b2 tsettings
whos N h LW b2 tsettings
disp('AFTER CLEARING SAVED HIDDEN VARIABLES')
disp('ENTER TO CONTINUE')
pause
load h.mat
load LW b2 tsettings
whos N h LW b2 tsettings
disp('AFTER RELOADING SAVED HIDDEN VARIABLES')
disp('ENTER TO CONTINUE')
pause
yn = b2 + LW*h;
y = mapminmax('reverse',yn,tsettings);
reloadingerror = max(abs(y-y0))
break
% Hope this helps
Thank you for formally accepting my answer
Greg
추가 답변 (1개)
Greg Heath
2013년 4월 13일
편집: Greg Heath
2013년 4월 13일
clear all, clc
[ x, t ] = simplefit_dataset;
net0 = fitnet( 10 );
[ net0 tr0 y0 ] = train( net0, x, t);
whos
%You can save the output and net
save y0 net0
%Delete them
clear y0 net0
whos
%and retrieve them
load y0 net0
whos
%or save, delete and and retrieve the weights
W0 = getwb(net0)
save y0 W0
whos
clear y0 W0
whos
load y0 W0
whos
Hope this helps.
Thank you for formally accepting my answer
Greg
댓글 수: 2
manel
2014년 4월 21일
hi ; I have the same problem ; if you have solve it can you pleez say me what you have done. thanks in advance
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!