1

I have a model content one encoder and two decoder with two loss function:

input_shape = (384, 512, 3)
model = Model(inputs=input, outputs=[1_features, 2_features])
model = build_model(input_shape, 3)
losses = {
"loss1_output": "categorical_crossentropy",
"loss2_output": "categorical_crossentropy"}

lossWeights = {"loss1_output": 1.0, "loss2_output": 1.0}
EPOCHS = 50
INIT_LR = 1e-3

opt = Adam(lr=INIT_LR, decay=INIT_LR / EPOCHS)
model.compile(optimizer=opt, loss=losses, loss_weights=lossWeights,
          metrics=["accuracy"])

I would combine the value for both those losses in one loss value and backward the result of the combination. My question is close to this one which I read and tried and I found the model called the loss function one time for each branch (output).

Zaher88abd
  • 448
  • 7
  • 20
  • Build a custom loss function where you combine your two losses and pass that as the loss when you compile the model. Here are what the default loss fuctions look like: https://github.com/keras-team/keras/blob/master/keras/losses.py. Just build your own based on a combination of the existing ones – Karl Nov 14 '18 at 20:14
  • That meaning I need to combine the two output to pass this to the custom loss function. Is there any another way? – Zaher88abd Nov 14 '18 at 20:19
  • Why wouldn't you want to do it like that? – Karl Nov 14 '18 at 20:21
  • Keras already combines the losses (that is what the loss weights are for). – Dr. Snoopy Nov 14 '18 at 21:23

0 Answers0