How to get the Class Names from a dlNetwork?

31 ビュー (過去 30 日間)
James McBrearty
James McBrearty 2024 年 11 月 25 日 15:43
コメント済み: James McBrearty 2024 年 11 月 27 日 16:44
Hi All,
I am moving my code from 2023b, to 2024b, and I want to make use of dlNetworks, and the trainnet function in general, to take advantage of the better performance. Most of the code has been fine, except for the move away from classify to minibatchpredict and scores2label.This is my current code, with a series network implementation:
yPred = classify(Model, xAll);
However, classify itself doesn't work with dlNetworks, and as such I have to move on to something like this, according to the documentation:
yPred = predict(Model, cell2mat(xAll)');
Predictions = scores2label(yPred,classNames);
The issue with this is that I have to explicitly save my classNames down, which I don't have to do in the seriesnetwork implementation, although I am aware that it is saved as a private property.
I am just asking is there a way that I can do something similar, where I don't have to save the classnames themselves? Otherwise it seems that seriesnetworks might be a better implementation.
Thanks in advance!

採用された回答

Matt J
Matt J 2024 年 11 月 25 日 18:06
編集済み: Matt J 2024 年 11 月 25 日 22:05
After you've trained the model as a dlnetwork, there is nothing stopping you from converting it back to a traditional SeriesNetwork and adding a classification layer for the purposes of prediction.
You could also define for yourself a custom layer,
to replace the traditional output layer. The idea is that you replace it with a layer which stores your class names and which does essentially the same thing as the legacy classification output layer, but because it is derived from the nnet.layer.Layer parent class, it would be compatible with dlnetwork(). With this approach, you would write the forward() method for the custom layer to ignore the class names for the purposes of training, while the predict() method would be written to use them.
  1 件のコメント
James McBrearty
James McBrearty 2024 年 11 月 27 日 16:44
Hi Matt,
Thanks for this! Worked a treat!

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

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by