gpt4 book ai didi

python - ValueError : Shapes (16, ) 和 (1, 16) 在 tensorflow1.0 中不兼容

转载 作者:太空宇宙 更新时间:2023-11-04 05:11:43 24 4
gpt4 key购买 nike

当我在tensorflow中运行以下代码时

import tensorflow as tf
import numpy as np

x_input_data = np.random.random((1024,16))
q = tf.train.input_producer(x_input_data, element_shape=[1,16])
input = q.dequeue() # It replaces our input placeholder
print (x_input_data.shape)
print (input.get_shape())

sess = tf.Session()
sess.run(tf.global_variables_initializer())
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(sess=sess, coord=coord)
example_batch = tf.train.batch([input], batch_size=1024, num_threads=4, capacity=40, enqueue_many=True)
for step in range(1000):
sess.run(example_batch)
coord.request_stop()
coord.join(threads)
sess.close()

出现以下错误

ValueError: Shapes (16,) and (1, 16) are not compatible

为什么会出现此错误?

最佳答案

来自 https://www.tensorflow.org/api_docs/python/tf/train/input_producer , element_shape 是行的形状,它引用一维 numpy 数组 (16,) 而不是提供的二维 numpy 数组 (1, 16)。如果您删除 element_shape 或将其替换为 `(16,),它应该可以工作。

关于python - ValueError : Shapes (16, ) 和 (1, 16) 在 tensorflow1.0 中不兼容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42818693/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com