I'd like to implement a custom loss function (specifically for this) for training a NN in Tensorflow, in which NN has two outputs, and the loss function is a formula involving both outputs and the expected output. How can I individually adress those? Examples from tensorflow it looks e.g. like:
def mean_absolute_percentage_error(y_true, y_pred):
y_pred = ops.convert_to_tensor(y_pred)
y_true = math_ops.cast(y_true, y_pred.dtype)
diff = math_ops.abs(
(y_true - y_pred) / K.clip(math_ops.abs(y_true), K.epsilon(), None))
return 100. * K.mean(diff, axis=-1)
What exactly are the tensors passed in here as y_true - what shape do they have? I haven't been able to find any documentation about that. All the examples I've seen for custom losses just calculate all outputs at once, whereas I need to pick out individual outputs.
Please note: I cannot define the network into two outputs and define a separate loss for each output, as the Model.compile documentation allows / as it is done here, since the loss function is a function of all three values.