![](/img/trans.png)
[英]Input 'y' of 'Mul' Op has type float32 that does not match type int32 of argument 'x'
[英]TypeError: Input 'y' of 'Mul' Op has type float32 that does not match type int32 of argument 'x'
在运行 tensorflow 时出现错误,如TypeError: Input 'y' of 'Mul' Op 的类型 float32 与参数 'x' 的类型 int32 不匹配。
我的代码是
import numpy as np
import pandas as pd
import tensorflow as tf
w = tf.Variable(0, dtype=tf.float32)
cost = tf.add(tf.add(w**2, tf.multiply(-10,w)), 25)
train = tf.train.GradientDescentOptimizer(0.001).minimize(cost)
init = tf.global_variables_initializer()
session = tf.session()
session.run(init)
session.run(w)
我正在运行 1.2.0 版有很多类似的问题,但不是很好的答案。 你能解释一下发生了什么吗? 提前致谢。
问题是你试图将一个整数(即 10)和一个浮点变量(w)相乘。 TensorFlow 需要输入类型匹配才能进行乘法运算。 因此,请确保您对tf.multiply
和tf.add
所有输入都是相同的类型。
改变你的线路,
cost = tf.add(tf.add(w**2, tf.multiply(-10,w)), 25)
到
cost = tf.add(tf.add(w**2, tf.multiply(-10.0,w)), 25.0)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.