Gradient clipping with custom feed-forward net

15 visualizaciones (últimos 30 días)
Christoph Aistleitner
Christoph Aistleitner el 28 de Jul. de 2021
Respondida: Artem Lensky el 4 de Dic. de 2022
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"?

Respuesta aceptada

Vineet Joshi
Vineet Joshi el 1 de Sept. de 2021
The following documentation link will provide you suitable details regarding dealing with exploding gradients in MATLAB.
Hope this helps.
  1 comentario
Artem Lensky
Artem Lensky el 4 de Dic. de 2022
The answer you provided is not for a custom loop. See this example 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.

Iniciar sesión para comentar.

Más respuestas (1)

Artem Lensky
Artem Lensky el 4 de Dic. de 2022
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);
You might also find this link useful that discuss detection of vanishing gradients in deep neural networks.


Más información sobre Image Data Workflows en Help Center y File Exchange.




Community Treasure Hunt

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

Start Hunting!

Translated by