Group Abstract Group Abstract

Message Boards Message Boards

Add a customized complex loss function to a neural network?

Posted 8 years ago
POSTED BY: Guy Malki
3 Replies
Posted 8 years ago

Let's try with more concrete example:

I created the following net:

![enter image description here][1]

It gets a 1X1X512 signal as "Input", and produces some manipulation through "unet" to achieve "Output", which is the desired signal (which resemble to the input signal), by calculating the standard loss.

In addition, "Output" enters to "smooth" layer to calculate the "smoothLoss".

However - the "Target" port for the two losses should be different: for the "output" calculation the target is as the input, and for the "smoothLoss" the target should be zero. I tried to implemented it as:

testTrain = NetTrain[fullNet, <|"Input" -> inputDataNorm, "Output" -> inputDataNorm, "smoothLoss" -> ConstantArray[0, Length[inputDataNorm]]|>, LossFunction -> {"Output", "smoothLoss"}]

But I got messy results, and I'm sure somthing is wrong with that code.

Can someone help me please ?

POSTED BY: Guy Malki
Posted 8 years ago

Thank you very much, Martijn. Can I define for each loss layer different "Target" and "Input" ports ? Where to do it ?

POSTED BY: Guy Malki

You can add as many loss layers layers as you want and by specifying the LossFunction in NetTrain you can say which Outputs of your network are the loss layers to use. For building a loss function you can just used the default net building blocks as you can see in the example below.

In this case NetTrain[ , LossFunction->{"Loss1","Loss2","Loss3"}]. As far as i understand anything will work as long as the output of your loss net is a Real value.

custom loss layers

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