I need to train a pattern recognition network in matlab. I have several datasets which shall be used for training. My script looks like this:
%%% train network with a couple of datasets
pathStr = 'Daten_Training';
files = dir(sprintf('%s/*.mat',pathStr));
for k = 1:length(files)
%%% load data for training
load(sprintf('%s/%s',pathStr, files(k).name));
%%% manually set targets to train the network with
Targets = setTargets(Data);
%%% create and train neural network
% Create a Pattern Recognition Network
hiddenLayerSize = 20;
net = patternnet(hiddenLayerSize);
% Train the network with our Data
net = trainNetwork(net,Data,Targets);
end
The trainNetwork
function looks like this:
function [ net ] = trainNetwork( net, Data, Targets )
% calculate features
[Features, TargetsBlock, blockIdx] = calcFeatures_Training(Data, Targets);
% split data for training
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;
% Train the network
[net, tr] = train(net, Features, TargetsBlock);
end
Is there a way to train multiple times with the same result as if I would use one training with all datasets in a row? For now it looks like the network is just retrained with the new data and everything before is lost.
Do not now it is actual or not, but maybe help for someone.
You can train a network only one times. If you train again, it is going to be a new network. :) The weights going to be different. If you give the same name, MATLAB going to overwrite every time you run the script.
The best way - i think - to do this is :
Hope this helps for somebody:)