Keras Custom loss function to pass arguments other than y_true and y_pred

前端 未结 2 2027
小蘑菇
小蘑菇 2020-11-30 10:15

I am writing a keras custom loss function where in I want to pass to this function the following: y_true, y_pred (these two will be passed automatically anyway), weights of

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-30 11:13

    You can do this another way by using the lambda operator as following:

    model.compile(loss= [lambda y_true,y_pred: Custom_loss(y_true, y_pred, val=0.01)], optimizer =...)

    There are some issues regarding saving and loading the model this way. A workaround is to save only the weights and use model.load_weights(...)

提交回复
热议问题