Open bjtho08 opened 3 years ago
Hi @bjtho08, thanks for reporting the issue. It seems that we only support 2D y_true
and y_pred
shaped like [batch_size, num_classes]
.
@WindQAQ do you know what kind of F1 impl we have in TF/Model?
@WindQAQ do you know what kind of F1 impl we have in TF/Model?
No, but I remember that they asked us if we can migrate F1 score very long time ago. Not sure if there is any follow-up.
@WindQAQ yes, I realized over the weekend as I was working on isolating the issue. I made a local copy, where I reshape y_true
and y_pred
using tf.reshape(tf.cast(y_true, self.dtype), [-1, self.num_classes])
and similar for y_pred
. I was wondering, do you know if it is possible to output several f1 scores to the keras training loop? Currently, if I bypass the tf.reduce_mean(f1_score)
, the end result is still just a simple mean
of the (in my case) 4 numbers returned from the F1Score.result()
method. I want to be able to see the F1 score for each class so that I can monitor all classes and make sure that it isn't just one or two of them that are performing well enough to outweigh the poor performance of the remaining classes.
@WindQAQ do you know what kind of F1 impl we have in TF/Model?
No, but I remember that they asked us if we can migrate F1 score very long time ago. Not sure if there is any follow-up.
Yes at https://github.com/tensorflow/tensorflow/pull/31818
We have also some F1 impl in official/NLP https://github.com/tensorflow/models/search?q=f1
Also we had an old thread about multi-class precision recall at https://github.com/tensorflow/addons/issues/1753
@WindQAQ yes, I realized over the weekend as I was working on isolating the issue. I made a local copy, where I reshape
y_true
andy_pred
usingtf.reshape(tf.cast(y_true, self.dtype), [-1, self.num_classes])
and similar fory_pred
. I was wondering, do you know if it is possible to output several f1 scores to the keras training loop? Currently, if I bypass thetf.reduce_mean(f1_score)
, the end result is still just a simplemean
of the (in my case) 4 numbers returned from theF1Score.result()
method. I want to be able to see the F1 score for each class so that I can monitor all classes and make sure that it isn't just one or two of them that are performing well enough to outweigh the poor performance of the remaining classes.
I'm afraid that it's impossible to do that if you use model.compile()
&& model.fit()
. It seems that somewhere in https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/keras/engine/training.py reduces the metrics output. One way I can think about is to write a custom callback and print {m.name: m.result() for m in self.metrics}
.
https://colab.research.google.com/drive/1G2HQ95iE2lqYub8i3O-kl5_mXMrIwmxg?usp=sharing
One way I can think about is to write a custom callback and print
{m.name: m.result() for m in self.metrics}
.https://colab.research.google.com/drive/1G2HQ95iE2lqYub8i3O-kl5_mXMrIwmxg?usp=sharing
@WindQAQ I realize this is well beyond the original issue, but how would you go about using that particular solution for batch-wise updates, like the keras progress bar, without losing the progress bar, of course.
System information
Describe the bug
Adding F1Score to a FCNN model with image input and output, the code fails during initalization with ValueError: shapes must be equal rank, but are 1 and 3 for '{{node AssignAddVariableOp_4}} = AssignAddVariableOp[dtype=DT_FLOAT](AssignAddVariableOp_4/resource, Sum_3)' with input shapes: [], [?,?,4].
I checked and the two tensors
y_true
andy_pred
have the shapes[None, None, None, None]
and[None, None, None, 4]
. Any other metric handles this just fine (e.g. the native accuracy metric in Keras or another custom metric, that I'm using), which leads me to believe it is a bug in the FBetaScore.I included a MWE with random data and the same error arises here. EDIT: I also tried running the model in eager mode, which gave a slightly different error. The traceback is posted at the bottom.
Code to reproduce the issue
Other info / logs
Traceback from eager mode