【问题标题】:How to fix 'Mul' Op has type float32 that does not match type int64?如何修复'Mul' Op 的 float32 类型与 int64 类型不匹配?
【发布时间】:2021-03-19 04:02:29
【问题描述】:
model.fit([training_pairs[:, 0], training_pairs[:, 1]],training_labels,batch_size=64, epochs=10)

纪元 1/10

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

TypeError: 'Mul' Op 的输入 'y' 的 float32 类型不匹配 键入参数“x”的 int64。

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

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

由于我对stackoverflow工具不太熟悉,所以我也放了我的笔记本链接。我正在使用 tensorflow 2.4 版。非常感谢您的帮助。

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

【问题讨论】:

  • 请在此处包含您的代码,而不是在 Colab 上

标签: python-3.x keras deep-learning tensorflow2.0 siamese-network


【解决方案1】:

如报错,需要将标签数据类型更改为'int64'

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

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

【讨论】:

    猜你喜欢
    • 2021-05-04
    • 2016-07-12
    • 1970-01-01
    • 1970-01-01
    • 2019-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-06
    相关资源
    最近更新 更多