lit*_*tle 4 reshape keras tensor
该Reshape层没有按照我的预期工作。在下面的例子中,我认为最后一行应该返回一个 shape 的张量对象[5,1]。但是会抛出一个错误,指出形状[5]张量不能重新整形为尺寸[5,5,1]张量。
>>> 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].
Run Code Online (Sandbox Code Playgroud)
有人可以解释一下 Reshape 层是如何工作的(即为什么要添加额外的暗淡)以及如何将向量重新整形为矩阵的过程?
谢谢
用户 Reshape(target_shape=(1,))(x)
将batch_size在整个模型隐含的,从开始到结束忽略。
如果您确实想访问批量大小,请使用K.reshape(x,(5,1)).
如果不创建完全由层组成的模型,则不应使用 Keras。
| 归档时间: |
|
| 查看次数: |
10539 次 |
| 最近记录: |