I am trying to compute a custom loss function in Keras using Categorical Cross entropy. I would like to create a unique loss function for both outputs (my network has 1 input and 2 outputs) that is:
L= lambda*L1+(1-lambda)*L2
where lambda is between 0 and 1 and L1 is the categorical loss entropy of the first output and L2 of the second... I tried like this:
def my_loss(y_true, y_pred):
final_loss = (0.8*(losses.binary_crossentropy(y_true[:, 0], y_pred[:, 0])+(0.2)*( losses.categorical_crossentropy(y_true[:, 1:], y_pred[:,1:]))))
return final_loss
and then:
model.compile(optimizer='Adam', loss=[my_loss],metrics=[metrics.categorical_accuracy])
But first problem is that i have still pass 2 times the function my loss and I don't know if is it correct; plus I can`t pass lambda to my_loss.
How can I do?