【问题标题】:Why does turning array into Tensor add dimensionality?为什么将数组转换为 Tensor 会增加维度?
【发布时间】: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


【解决方案1】:

在输入层,必须指定ragged=True,这样这个维度就被忽略了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-09-07
    • 1970-01-01
    • 2011-02-14
    • 2018-06-30
    • 1970-01-01
    • 2014-06-03
    • 1970-01-01
    相关资源
    最近更新 更多