'How to fix 'Mul' Op has type float32 that does not match type int64?

model.fit([training_pairs[:, 0], training_pairs[:, 1]],training_labels,batch_size=64, epochs=10)

Epoch 1/10

model.fit([training_pairs[:, 0], training_pairs[:, 1]],training_labels,batch_size=64, epochs=10)

TypeError: Input 'y' of 'Mul' Op has type float32 that does not match type int64 of argument 'x'.

print(training_labels.dtype)
dtype('int64')

print(training_pairs.dtype)
dtype('float32')

As I am not quite familiar with the stackoverflow tool,I have put my notebook link also. I am using tensorflow version 2.4. Much appreciate for your help.

https://colab.research.google.com/drive/1z4ubLpnvPk6RWGCviCW6z_xMZ5t64gUP?usp=sharing



Solution 1:[1]

As shown in error, you need to change the label data type as below which is 'int64':

training_labels = tf.cast(training_labels, tf.float32)
training_labels.dtype

OR

training_labels=training_labels.astype('float32')
training_labels.dtype

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 TFer2