Are dlnetworks supposed to be allowed to have output layers?
11 次查看(过去 30 天)
显示 更早的评论
Are dlnetworks allowed to have output layers? In the following code, I manage to create one, so the answer would seem to be yes.
layers= [imageInputLayer([1,1,1]) , reluLayer(Name='relu') ] ;
dln = replaceLayer( dlnetwork(layers) ,'relu', regressionLayer);
class(dln)
dln.Layers
However, when I try to create this more directly, an error is raised:
dln = dlnetwork( [imageInputLayer([1,1,1]) , regressionLayer] )
Have I found an unintended backdoor?
0 个评论
采纳的回答
Jack
2025-3-28
By design, dlnetwork objects are intended for custom training loops and are not supposed to include output layers like regressionLayer or classificationLayer. If you try to create a dlnetwork directly with an output layer, MATLAB throws an error. The fact that replaceLayer can slip in an output layer is effectively a workaround, but it isn’t officially supported.
Follow me so you can message me anytime with future questions. If this helps, please accept the answer and upvote it as well.
3 个评论
Jack
2025-4-1
Regarding documentation, while you might not find an explicit statement saying “dlnetwork objects must not contain output layers,” the behavior and error messages in MATLAB reflect this design choice. The documentation and examples for dlnetwork consistently show networks built without an output layer, reinforcing that output layers are meant to be handled externally in your training loop.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Data Workflows 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!