gpt4 book ai didi

python - 队列形状必须与数据类型具有相同的长度

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

我正在尝试初始化一个类似于我的 numpy 数组形状的 FIFOQueue但出现以下错误。

我的 - numpy 数组形状 - (1, 17428, 3)

dtypes=[tf.float32,tf.float32,tf.float32]
print len(dtypes)
shapes=[1, 17428, 3]
print len(shapes)
q = tf.FIFOQueue(capacity=200,dtypes=dtypes,shapes=shapes)

ValueError: Queue shapes must have the same length as dtypes

最佳答案

documentation指定 FIFOQueue 的构造函数的参数是(强调我的):

  • dtypes: A list of DType objects. The length of dtypes must equal the number of tensors in each queue element.
  • shapes: (Optional.) A list of fully-defined TensorShape objects with the same length as dtypes, or None.

不过,您指定为 shapes 的内容并不是完全定义的 TensorShape 对象的列表。它是一个包含三个维度的列表,将被解释为一个 TensorShape 导致 shapes=[TensorShape([Dimension(1), Dimension(17428), Dimension(3)])] 长度为 1。要告诉构造函数您需要三个一维张量,您可以指定:

shapes=[tf.TensorShape(1), tf.TensorShape(17428), tf.TensorShape(3)]

然后 q = tf.FIFOQueue(capacity=200,dtypes=dtypes,shapes=shapes) 将运行并且不会引发错误。

关于python - 队列形状必须与数据类型具有相同的长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47297263/

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