0
無法將列表提供給Tensorflow feed_dict。的代碼:帶有浮動列表和InvalidArgumentError列表的Tensorflow feed_dict
import tensorflow as tf
import numpy as np
from sklearn.model_selection import train_test_split
from math import ceil
BATCH_SIZE = 100
# Create 100 phony x, y data points in NumPy, y = x * 0.1 + 0.3
x_data = np.random.rand(13000).astype(np.float32)
y_data = x_data * 0.1 + 0.3
x_train, x_test, y_train, y_test = train_test_split(x_data, y_data, test_size=0.3)
# Try to find values for W and b that compute y_data = W * x_data + b
# (We know that W should be 0.1 and b 0.3, but TensorFlow will
# figure that out for us.)
x_in = tf.placeholder(tf.float32, shape=[BATCH_SIZE], name='x_in')
y_in = tf.placeholder(tf.float32, shape=[BATCH_SIZE], name='y_in')
W = tf.Variable(tf.random_uniform([1], -1.0, 1.0))
b = tf.Variable(tf.zeros([1]))
y = W * x_in + b
# Minimize the mean squared errors.
loss = tf.reduce_mean(tf.square(y - y_in))
optimizer = tf.train.GradientDescentOptimizer(0.5)
train = optimizer.minimize(loss)
# Before starting, initialize the variables. We will 'run' this first.
init = tf.global_variables_initializer()
# Launch the graph.
sess = tf.Session()
sess.run(init)
batchesCount = ceil(len(x_train)/BATCH_SIZE)
# Fit the line.
for curBatchId in range(batchesCount):
batchStart = curBatchId * BATCH_SIZE
xf = x_train[batchStart: BATCH_SIZE]
yf = y_train[batchStart: BATCH_SIZE]
sess.run(train, feed_dict={x_in: xf, y_in:yf})
給我:
InvalidArgumentError(參見上述用於回溯):必須喂值 爲佔位符張量 'x_in' 與D型浮子和形狀[100]
[ [節點:x_in = Placeholderdtype = DT_FLOAT,形狀= [100], _device = 「/作業:本地主機/複製:0 /任務:0/CPU:0」]]
什麼錯誤代碼中的,對我而言像它傳遞
佔位符張量 'x_in' DTYPE的浮子和形狀[100]
?