【发布时间】:2019-01-17 11:54:58
【问题描述】:
Reshape 层没有按我的预期工作。在下面的示例中,我认为最后一行应该返回一个形状为[5,1] 的张量对象。但是会抛出一个错误,指出形状 [5] tensor 不能重新整形为大小 [5,5,1] tensor。
>>> from keras.layers import Reshape
>>> from keras import backend as K
>>> import numpy as np
>>> x = K.constant(np.array([1,2,3,4,5]))
>>> K.eval(x)
array([1., 2., 3., 4., 5.], dtype=float32)
>>> Reshape(target_shape=(5,1))(x)
...
ValueError: Cannot reshape a tensor with 5 elements to
shape [5,5,1] (25 elements) for 'reshape_3/Reshape' (op:
'Reshape') with input shapes: [5], [3] and with input
tensors computed as partial shapes: input[1] = [5,5,1].
有人可以解释一下 Reshape 层是如何工作的(即为什么要添加额外的暗淡)以及如何将向量重塑为矩阵的过程?
谢谢
【问题讨论】: