Expected to be a float tensor but is a double tensor with tf.keras.metrics.AUC()

Following the tutorial of Turning quantum nodes into Keras Layers. I changed the compile method to the following:

model.compile(opt, loss="mae", metrics=["accuracy", tf.keras.metrics.AUC()])

This gave the following error:

InvalidArgumentError: cannot compute Mul as input #1(zero-based) was expected to be a double tensor but is a float tensor [Op:Mul]

I am using tf.keras.backend.set_floatx('float64'). Any help on this is appreciated.

Thank you.

Hey @Gopal_Dahale!

I can confirm that I reproduced your error. The problem is with your use of tf.keras.metrics.AUC() as a metric that you’d like to evaluate during training.

When we say double tensors, we mean Float64 tensors, and float tensors refer to Float32 tensors. Pytorch also has this convention.

Anywho, to your question, if you change your backend to tf.keras.backend.set_floatx('float32') it works on my end :slight_smile:. Do you need float64?