필터 지우기
필터 지우기

re training neural network from previous state using trainNetwork

조회 수: 17 (최근 30일)
Avi Sulimarski
Avi Sulimarski 2021년 4월 29일
댓글: Xie Shipley 2023년 11월 16일
Hi
I am training a deep neural network , using the following matlab function:
net = trainNetwork(XTrain,YTrain,layers,options);
could I use the trainNetwork command to retrain the network (not from scratch), using the last network state from previous training?
I am sharing some of the code:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
layers = [
imageInputLayer([1 Nin 5],"Name","imageinput")
convolution2dLayer([1 3],32,"Name","conv","Padding","same")%
%batchNormalizationLayer('Name','batchDown')
tanhLayer("Name","tanh1")
convolution2dLayer([1 3],32,"Name","conv","Padding","same","DilationFactor",[1 3])%
%batchNormalizationLayer('Name','batchDown1')
tanhLayer("Name","tanh2")
convolution2dLayer([1 3],2,"Name","conv","Padding","same","DilationFactor",[1 9])%
regressionLayer];
options = trainingOptions('adam', ...
'InitialLearnRate',0.001, ...
'MaxEpochs',50000, ...
'ExecutionEnvironment','parallel',...
'Verbose',false, ...
'Plots','training-progress');
Net1 = trainNetwork(XTrain1,YTrain1,layers,options);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
now I would like to train again getting Net2 using new data, and starting the training from Net1 stage.
for example:
Net2 = trainNetwork(XTrain2,YTrain2,layers,options);
however its not clear to me how to start the train process for Net2 using Net1 stage.

채택된 답변

Yomna Genina
Yomna Genina 2021년 5월 5일
You can do the following if Net1 is a SeriesNetwork:
Net2 = trainNetwork(XTrain2, YTrain2, Net1.Layers, options);
or if Net1 is a DAGNetwork:
Net2 = trainNetwork(XTrain2, YTrain2, layerGraph(Net1), options);
This will train using Net1 as the initial network.
If you would also like to prevent weights in certain layers from changing, you could use freezeWeights (see how to access it below). This function could be used to set the learning rates in those layers to zero. During training, trainNetwork does not update the parameters of the "frozen" layers.
edit(fullfile(matlabroot,'examples','nnet','main','freezeWeights.m'))
You might find the following documentation pages useful:
Hope this helps!
  댓글 수: 4
NASRIN AKTER
NASRIN AKTER 2022년 6월 4일
Hi Yomna
Is it necessary to save the checkpoint networks as shown in the 1st link?
Also can you suggest any example of incremental learning for image classification using deep learning?
Thanks
Xie Shipley
Xie Shipley 2023년 11월 16일
If using "population" in `trainingOption`,will the mean and variance of the Net2(it's mean and variance is same as Net1 when stop training Net1) changing while training ? @Yomna Genina

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Data Workflows에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by