Python 提要的值不能是tf.Tensor对象
我正在尝试读取cifar10数据集并将其用于训练模型,因此我尝试读取批并按如下方式运行会话:Python 提要的值不能是tf.Tensor对象,python,tensorflow,deep-learning,neural-network,conv-neural-network,Python,Tensorflow,Deep Learning,Neural Network,Conv Neural Network,我正在尝试读取cifar10数据集并将其用于训练模型,因此我尝试读取批并按如下方式运行会话: # Optimizer opt = tf.train.AdamOptimizer(0.0001) global_step = tf.get_variable('global_step', initializer=tf.constant(0), trainable=False) train_op = opt.apply_gradients(zip(grads, var_list)
# Optimizer
opt = tf.train.AdamOptimizer(0.0001)
global_step = tf.get_variable('global_step', initializer=tf.constant(0), trainable=False)
train_op = opt.apply_gradients(zip(grads, var_list), global_step=global_step)
(x_train, y_train), (x_test, y_test) = keras.datasets.cifar10.load_data()
image_batch, label_batch = tf.train.batch([x_train, y_train], batch_size=batch_size)
#image_batch_uint8 = tf.cast(image_batch, tf.uint8)
# Train
with tf.Session() as sess:
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(sess=sess, coord=coord)
sess.run(tf.global_variables_initializer())
for i in range(10000000):
_loss_value, _reward_value, _ = sess.run([loss, reward, train_op], feed_dict={
images_ph: image_batch,
labels_ph: label_batch
})
if i % 100 == 0:
print('iter: ', i, '\tloss: ', _loss_value, '\treward: ', _reward_value)
但是我得到了这个错误:
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 900, in run
run_metadata_ptr)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 1086, in _run
'feed with key ' + str(feed) + '.')
The value of a feed cannot be a tf.Tensor object. Acceptable feed values include Python scalars, strings, lists, numpy ndarrays, or TensorHandles.For reference, the tensor object was Tensor("batch:0", shape=(32, 50000, 32, 32, 3), dtype=uint8) which was passed to the feed with key Tensor("Placeholder:0", shape=(?, 1024), dtype=float32).
我做错了什么?我不确定错误是什么。
image\u batch
和label\u batch
是tf.tensor(不是numpy数组)。使用feed\u dict
馈送数据时,只能馈送numpy数组/列表。非常感谢!然而,使用tf.train.batch时,我总是会得到张量,我看不到一种将它们转换为numpy数组的简单方法。你有什么建议吗?看来我需要开个会?有没有更好的方法来获取批处理,那么我想知道,如果你看到它将被弃用。所以我建议您使用,tf.data
。