When I use the following custom metric (keras-style):
from sklearn.metrics import classification_report, f1_score
from ten
Add this line after importing tensorflow:
tf.compat.v1.disable_eager_execution()
then using @tf.function(experimental_relax_shapes=True) will probably solve your problem
This warning occurs when a TF function is retraced because its arguments change in shape or dtype (for Tensors) or even in value (Python or np objects or variables).
In the general case, the fix is to use @tf.function(experimental_relax_shapes=True) before the definition of the custom function that you pass to Keras or TF somewhere. This tries to detect and avoid unnecessary retracing, but is not guaranteed to solve the issue.
In your case, i guess the Predictor class is a custom class, so place @tf.function(experimental_relax_shapes=True) before the definition of Predictor.predict().