Save net for later genFunction function call

I'm using the Neural Network framework to generate with genFunction the weights and other parameters that I use to encapsulate into another project. In my case, the parameters I get with genFunction are x1_step1, y1_step1, b1,b2, IW_1, LW_2.
I'd like to run a batch of trainings, then get those parameters from every network I train, and using genFunction all over the batch would be unusefull. However, creating an array of nets and concatenating them into the for loop seems not working: I only get an unreadable network cell. I tried using struct(net) and I successfully got an array row that can be concatenated, but I cannot cast the rows it to a net with cast(netarray, 'net').
The purpose I want to achieve is using the best MAE in the batch to get the corresponding net's weights.
How do I solve this problem?
here it is the code
trainFcn = 'trainbr'; %Bayesan backprop.
netMAE_OUT = [];
netArray = [];
hiddenLayerSize = 3;
trainsize = 2;
step = 12;
net = fitnet(hiddenLayerSize,trainFcn);
for c = 1:trainsize
% Setup Division of Data for Training, Validation, Testing
net.divideParam.trainRatio = 65/100;
net.divideParam.valRatio = 20/100;
net.divideParam.testRatio = 15/100;
for i = 1:5
%divide training and target set
xloop = [x(:,1:step*(i-1),:) x(:,step*i+1:end,:)];
tloop = [t(:,1:step*(i-1)) t(:,step*i+1:end)];
% Train the Network
[net,tr] = train(net,xloop,tloop);
y = net(x);
e = gsubtract(t,y);
%%here there is my try to save the network.
netArray = [netArray struct(net)];
mae_target = mae(e)
netMAE_OUT = [netMAE_OUT mae_target];
end
end

Answers (0)

Categories

Find more on Deep Learning Toolbox in Help Center and File Exchange

Asked:

on 10 Nov 2017

Edited:

on 10 Nov 2017

Community Treasure Hunt

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

Start Hunting!