Having problems with the trainnet function

13 ビュー (過去 30 日間)
Andrew
Andrew 2024 年 5 月 27 日
編集済み: Jayanti 2024 年 10 月 14 日
I am trying to fine tune a machine learning model. While using the trainnet function it states "Training stopped: Training loss is NaN" in the command window. The old trainNetwork functions works, which to me makes it weird that trainnet does not. How do I work around this? Possible solutions?
  1 件のコメント
Matt J
Matt J 2024 年 5 月 27 日
編集済み: Matt J 2024 年 5 月 27 日
Please post enough of your code for us to run and reproduce the problem. Please also post the code as formatted text, e.g.,
imageSize=[256,384];
rather than as an image, so that it can be easily copy/pasted.

サインインしてコメントする。

回答 (1 件)

Jayanti
Jayanti 2024 年 10 月 14 日
編集済み: Jayanti 2024 年 10 月 14 日
Hi Andrew,
I tried to run the code you provided on custom dataset, and it is working fine as you can see in the attached image.
Without actual data, it is difficult to provide a definitive solution upfront. However, the following two options can be explored to address this issue:
  1. Adjusting learning rate – If learning rate is very high it can cause the model to diverge, leading to NaN values. So, try reducing the learning rate.
  2. Gradient Clipping - Consider adding gradient clipping to prevent exploding gradients.
Hope it helps!

カテゴリ

Help Center および File ExchangeImage Data Workflows についてさらに検索

製品


リリース

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by