Gradient clipping with custom feed-forward net

조회 수: 14 (최근 30일)
Christoph Aistleitner
Christoph Aistleitner 2021년 7월 28일
답변: Artem Lensky 2022년 12월 4일
Everytime I am training my custom feed-forward net with 2 inputs and one output( timeseries) with the train(net,....) function:
after ~10 training epochs the value of the gradient reaches the prestet value and the training stops.
Changing the networks architecture is not an option in my case.
Is there a way to implement "gradient clipping" with a feed-forward net?
Or is there any other workaround for the "exploding gradient"?

채택된 답변

Vineet Joshi
Vineet Joshi 2021년 9월 1일
Hi
The following documentation link will provide you suitable details regarding dealing with exploding gradients in MATLAB.
Hope this helps.
Thanks
  댓글 수: 1
Artem Lensky
Artem Lensky 2022년 12월 4일
The answer you provided is not for a custom loop. See this example https://au.mathworks.com/help/deeplearning/ug/train-network-using-custom-training-loop.html there is the following line
[loss,gradients,state] = dlfeval(@modelLoss,net,X,T);
The question is how to apply clipping to gradients. Is there are standard Matlab function can do this for me or should I implement it myself.

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

추가 답변 (1개)

Artem Lensky
Artem Lensky 2022년 12월 4일
Please check this link that illustrates several examples on how to implement training options that you would usually define via trainingOptions() and use with trainNetwork() but for customs loops. Here is an L2 clipping example given in the link above
function gradients = thresholdL2Norm(gradients,gradientThreshold)
gradientNorm = sqrt(sum(gradients(:).^2));
if gradientNorm > gradientThreshold
gradients = gradients * (gradientThreshold / gradientNorm);
end
end
You might also find this link useful https://au.mathworks.com/help/deeplearning/ug/detect-vanishing-gradients-in-deep-neural-networks.html that discuss detection of vanishing gradients in deep neural networks.

카테고리

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

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by