"size of predictions and target values must match" when using custom loop training for multi-input and multi-output
45 次查看(过去 30 天)
显示 更早的评论
Dear all,
I build a deep learning model with 2 input and 2 output and use a custom loop training. But I have an error when call dlfeval(): "size of predictions and target values must match" . What should I fix? Here is my code:
[grad,state,loss] = dlfeval(@modelGradientsMulti, dlnet, input1, input2, output1, output2);
%support function
function [gradients,state,loss] = modelGradientsMulti(dlnet,in1,in2,out1,out2)
[pre1,pre2,state] = forward(dlnet,in1,in2,'Outputs',["fc1" "fc2"]);
loss1 = mse(pre1,output1);
loss2 = mse(pre2,output2);
loss = loss1 + loss2;
gradients = dlgradient(loss,dlnet.Learnables);
end
Thank you for reading my question. I hope someone expert will give a help.
2 个评论
Katja Mogalle
2022-1-21
From the error message my first guess would be that pre1 and output1 don't have the same size, or that pre2 and output2 don't have the same size. Can you put a breakpoint at the line where you compute mse for the first time and check the sizes of pre1, output1, pre2, and output2? If there are inconsistencies between the sizes we need to look further if the data or the network is set up incorrectly.
To better understand the sizes of activations in the network, I always suggest using analyzeNetwork:
>> analyzeNetwork(dlnet)
Let me know how you get on and what you find.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Sequence and Numeric Feature Data Workflows 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!