1

I want to define a loss function, and the loss of y_true is what I'm not going to use, but what I'm going to get from an external global variable.I found that after I passed the defined loss function to the model compile, it was called only once.I thought he was going to call batch_size once.Because I added a print to my custom loss function, but it only printed once.So I want to know how many times the custom loss function is called.

def my_loss(y_true, y_pred):

    global loss_count
    loss_count += 1
    print("the loss",loss_count)
    return keras.losses.categorical_crossentropy(y_true, y_pred)

After model training, the variable loss count is equal to 1

DaDaQiZi
  • 11
  • 1

0 Answers0