MATLAB Answers

Can I define a custom loss function using intermediate features?

1 ビュー (過去 30 日間)
Sangmin Park
Sangmin Park 2021 年 6 月 23 日
コメント済み: Sangmin Park 2021 年 7 月 2 日
I'm trying to customize my regression layer.
And I want to use intermediate features to my loss function.
Is there any way of utilizing features to customized loss function?
Looking forward to your answers.
Thank you for reading.

採用された回答

Katja Mogalle
Katja Mogalle 2021 年 7 月 2 日
Hi Sangmin,
I understand you want to define a loss function that requires ground truth data, intermediate network activations, and the final network output as input.
To implement such a loss function, you need to use the custom training loop approach instead of using trainNetwork. You can see an example here: Train Network Using Custom Training Loop.
If you look at the modelGradients function in that example, you'll be able to extract intermediate activations from the dlnetwork in the call to forward using the 'Outputs' name-value pair. And then you can formulate your own loss function without needing a regression layer.
There are already several typical loss functions available that you can make use of in your custom code, if applicable.
I hope this helps.
  1 件のコメント
Sangmin Park
Sangmin Park 2021 年 7 月 2 日
Thank you for your kind answer!

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

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by