Python 3.x 类型错误:输入';b';属于';马特穆尔';Op的float32类型与参数';a';-即使在铸造之后

Python 3.x 类型错误:输入';b';属于';马特穆尔';Op的float32类型与参数';a';-即使在铸造之后,python-3.x,tensorflow,Python 3.x,Tensorflow,当我尝试运行以下程序时,出现以下错误 TypeError:“MatMul”Op的输入“b”的类型float32与参数“a”的类型int32不匹配 我想它说\ux是int32类型,但我已经使用tf.cast来转换它了 import tensorflow as tf import numpy as np x = ([[3, 4, 5], [1, 2, 3], [3, 2, 5]]) y = ([[1, 2, 3, 4, 5, 6, 7, 8], [5, 3, 2, 5, 2, 6, 2, 5],

当我尝试运行以下程序时,出现以下错误

TypeError:“MatMul”Op的输入“b”的类型float32与参数“a”的类型int32不匹配

我想它说
\ux
int32
类型,但我已经使用
tf.cast来转换它了

import tensorflow as tf
import numpy as np

x = ([[3, 4, 5], [1, 2, 3], [3, 2, 5]])
y = ([[1, 2, 3, 4, 5, 6, 7, 8], [5, 3, 2, 5, 2, 6, 2, 5], [3, 2, 2, 5, 2, 4, 2, 7]])

tf.cast(x, tf.float32)
tf.cast(y, tf.float32)

train_x = np.asarray([3.3, 4.4, 5.5, 6.71, 6.93, 4.168, 9.779, 6.182, 7.59, 2.167,
    7.042, 10.791, 5.313, 7.997, 5.654, 9.27, 3.1], dtype=float)
train_y = np.asarray([1.7, 2.76, 2.09, 3.19, 1.694, 1.573, 3.366, 2.596, 2.53, 1.221,
    2.827, 3.465, 1.65, 2.904, 2.42, 2.94, 1.3], dtype=float)

learning_rate = 0.01
training_epochs = 100
batch_size = 10

n_hidden_1 = 256  # number of neurons in first hidden layer
n_hidden_2 = 256  # ,,      ...      ,,, second hidden layer
n_input = 50  # Dimension of feature used
n_output = 8  # Number of output neurons

weights = {
    'hidden_1': tf.Variable(tf.random_normal([n_input, n_hidden_1])),  # Randomly initialising weights
    'hidden_2': tf.Variable(tf.random_normal([n_hidden_1, n_hidden_2])),  # Randomly initialising weights
    'out': tf.Variable(tf.random_normal([n_hidden_2, n_output]))
}
biases = {
    'b1': tf.Variable(tf.random_normal([n_hidden_1])),
    'b2': tf.Variable(tf.random_normal([n_hidden_2])),
    'out': tf.Variable(tf.random_normal([n_output]))
}


def mlp(_x, _weights, _biases):  # Feed forward net / Multi layer perceptron
    # Defining layers

    layer_1 = tf.nn.relu(tf.add(tf.matmul(_x, _weights['hidden_1']), _biases['b1']))
    # Choose appropriate activation here
    layer_2 = tf.nn.relu(tf.add(tf.matmul(layer_1, _weights['hidden_2']), _biases['b2']))
    # layer_2 = tf.nn.relu()

    # Linear activation for output
    out_layer = tf.add(tf.matmul(layer_2, _weights['out']), _biases['out'])
    return out_layer


prediction = mlp(x, weights, biases)
tf.cast()。它返回对强制转换张量的引用,之后需要使用该张量;i、 e:

x = tf.cast(x, tf.float32)
y = tf.cast(y, tf.float32)
tf.cast()。它返回对强制转换张量的引用,之后需要使用该张量;i、 e:

x = tf.cast(x, tf.float32)
y = tf.cast(y, tf.float32)