Background
I have a multi-label classification problem with 5 labels (e.g. [1 0 1 1 0]
). Therefore, I want my model to improve at metrics such as fixed recall, precision-recall AUC or ROC AUC.
It doesn't make sense to use a loss function (e.g. binary_crossentropy
) that is not directly related to the performance measurement I want to optimize. Therefore, I want to use TensorFlow's global_objectives.recall_at_precision_loss()
or similar as loss function.
- Relevant GitHub: https://github.com/tensorflow/models/tree/master/research/global_objectives
- Relevant paper (Scalable Learning of Non-Decomposable Objectives): https://arxiv.org/abs/1608.04802
Not metric
I'm not looking for implementing a tf.metrics
. I already succeeded in that following: https://stackoverflow.com/a/50566908/3399066
Problem
I think my issue can be divided into 2 problems:
- How to use
global_objectives.recall_at_precision_loss()
or similar? - How to use it in a Keras model with TF backend?
Problem 1
There is a file called loss_layers_example.py
on the global objectives GitHub page (same as above). However, since I don't have much experience with TF, I don't really understand how to use it. Also, Googling for TensorFlow recall_at_precision_loss example
or TensorFlow Global objectives example
won't give me any clearer example.
How do I use global_objectives.recall_at_precision_loss()
in a simple TF example?
Problem 2
Would something like (in Keras): model.compile(loss = ??.recall_at_precision_loss, ...)
be enough?
My feeling tells me it is more complex than that, due to the use of global variables used in loss_layers_example.py
.
How to use loss functions similar to global_objectives.recall_at_precision_loss()
in Keras?