简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM