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

2024-04-27 03:21:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图初始化一个类似于我的numpy数组形状的fifoquee 但是得到下面的错误。在

My-numpy数组形状-(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

Tags: numpylenmytf错误数组形状capacity
1条回答
网友
1楼 · 发布于 2024-04-27 03:21:01

documentation指定FIFOQueue构造函数的参数是(emphasis mine):

  • 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,结果是长度为1的shapes=[TensorShape([Dimension(1), Dimension(17428), Dimension(3)])]。要告诉构造函数您需要三个1D张量,可以指定:

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

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

相关问题 更多 >