Now, since I'm not sure about what are g, q, x an y in your function, I'll just create a basic example here without caring about what it means or whether it's an actual useful function:import keras.backend as Kdef customLoss(yTrue,yPred): return K.sum(K.log(yTrue) - K.log(yPred))所有后端功能都可以在此处看到: https://keras.io/backend/#backend-功能All backend functions can be seen here: https://keras.io/backend/#backend-functions然后,使用该函数而不是常规函数来编译模型:After that, compile your model using that function instead of a regular one:model.compile(loss=customLoss, optimizer = .....) 这篇关于Keras中的自定义损失函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-27 20:36