Message Boards Message Boards

1
|
4044 Views
|
1 Reply
|
4 Total Likes
View groups...
Share
Share this post:

ThreadingLayer as a custom LossFunction?

Posted 2 years ago

Hi, As MeanSquaredLossLayer did not seem a suitable LossFunction for my network, I wanted to try other LossFunctions. The documentation says that you can use 'any network with an "Input" and optional "Target" port' as a LossFunction, but it was not clear to me how I can create a network that calculates a custom LossFunction. MeanSquaredLossLayer accepts two Array input ports and produces one Real output port, I guess it does something like

Total[(#1-#2)^2]/Length[#1]

I looked at ThreadingLayer, it accepts two Array input ports but produces an Array output port, so I expected I could not use it as a LossFunction. But when I specify

LossFunction->ThreadingLayer[(#1 - #2)^2 &, InputPorts -> {"Input", "Target"}]

I do not get an error and the loss seams similar to what I get with MeanSquaredLossLayer, so this suggests that ThreadingLayer can be used for custom LossFunctions. Any idea why this works? 'What' turns the Array output of ThreadingLayer into a Real output?

Thanks, GW

When the net specified in LossFunction produces an array (not a scalar number), a SummationLayer[] is automatically added. So the total of the numbers in the output array is used as a loss.

Thanks for spotting, we will add a note in the documentation of LossFunction.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract