TypeError: Input 'b' of 'MatMul' Op has type float32 that does not match type float64 of argument 'a

显示,TypeError: Input ‘b’ of ‘MatMul’ Op has type float32 that does not match type float64 of argument 'a,这是由于两个相乘矩阵类型不匹配,调试一下发现x矩阵为tf.float64,W矩阵为tf.float32,改类型用tf.cast()函数
修改前:

a=tf.nn.sigmoid(tf.matmul(XX,w1)+b1)
y=tf.nn.sigmoid(tf.matmul(a,w2)+b2)

修改后

a=tf.nn.sigmoid(tf.matmul(tf.cast(XX,tf.float32),w1)+b1)
y=tf.nn.sigmoid(tf.matmul(tf.cast(a,tf.float32),w2)+b2)

你可能感兴趣的:(python,机器学习)