0

I want to minimize the loss function of F1 and cross entropy, say my loss function is:

loss = a * cross_entropy_loss + (1-a) * (F1_value_loss)

Sine F1 value is non-differentiable function, and tensorflow do not supply a way to calculate F1 loss's approximate gradient, so I want to define my own gradient for F1_value_loss at the first time to optimize whole network, and use cross_entropy_loss's built-in gradient in tensorflow.So how can I define my own gradient for F1_value_loss and combine it to cross_entropy_loss, then propagate the loss to previous layers? Thx.

Peng He
  • 2,023
  • 5
  • 17
  • 24
  • Possible duplicate of [Tensorflow: How to replace or modify gradient?](https://stackoverflow.com/questions/43839431/tensorflow-how-to-replace-or-modify-gradient) – pfm Mar 14 '18 at 13:15
  • In particular, have a look to https://www.tensorflow.org/api_docs/python/tf/RegisterGradient – pfm Mar 14 '18 at 13:17
  • @npf I have read w.r.t questions. But I'm confusing that whether tensorflow calculate gradients layer by layer. I just want to modify the loss functions's first step(top layer) gradient and propagate it to previous layers. The w.r.t question is just replacing some specific gradient.Should I use some optimizer's compute_gradients and modify all variable gradients and then apply_gradients? What the the pipline to process this problem? I'm confusing... – Peng He Mar 15 '18 at 05:46

0 Answers0