When the third argument to NetTrain is set to Automatic, how can you tell what loss function it actually used and extract it?

Looking at the docs, I don't see it as a property that can be asked for in the fourth argument.


2 Answers 2


I agree it would be nice if you could query this information interactively from the progress window after starting a training session. But using a property (4th argument of NetTrain) you can explicitly ask for the 'loss network', which is the network in which loss layers have been attached and which is used to actually do the training.

net = LinearLayer[];
data = {1 -> 1.9, 2 -> 4.1, 3 -> 6.0, 4 -> 8.1};
NetTrain[net, data, Automatic, "LossNet", MaxTrainingRounds -> 1]

In this case you'll see it is a NetGraph that uses a MeanSquaredLossLayer. If the net already has loss layers the loss network is typically the same as the training network.

The actaul internal function is NeuralNetworks`AttachLoss[net, spec] if you want access to it directly. You can leave spec off if you just want the automatic choice.

  • 1
    $\begingroup$ The "LossNet" argument does not appear to work in version 11.3. Is there a new way to get the information? $\endgroup$ Aug 10, 2018 at 18:13

In the doc of NetTrain,it says

When a loss layer is chosen automatically for a port, the loss layer to use is based on the layer within the net whose output is connected to the port

enter image description here

  • $\begingroup$ But what is it exactly, are there explicit rules for each type of layer? $\endgroup$
    – M.R.
    Sep 2, 2017 at 1:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.