【发布时间】:2020-11-16 08:17:37
【问题描述】:
当我将我的 ndarray 变成 Ragged Tensor 时,会无缘无故地添加维度,从而导致错误:ValueError: Input 0 of layer sequential_8 is incompatible with the layer: expected ndim=3, found ndim=4. Full shape received: [None, None, None, None]
运行此代码后,观察会发生什么:
print(XTrain.shape)
x_train = tf.ragged.constant(XTrain)
print(x_train.shape)
print(XTrain[1].shape)
print(x_train[1].shape)
(10000,) (10000,无,无,无) (821, 1, 26) (821,无,无)
如您所见,不仅参差不齐的张量失去了故意添加的维度 np.ndarray: (821,1,26) --> tf.ragged.constant --> (821, None, None )
如何确保它不添加触发上述 ValueError 的随机三个非?
【问题讨论】:
-
好吧,RaggedTensor 不应该有固定的尺寸
-
我提交了issue #40159关于这个确切的问题。
-
有什么办法可以解决吗?我不知道为什么它检测到的形状是 [None, None, None, None]...很奇怪...
标签: python arrays tensorflow keras lstm