在 Keras 函数式 API 中重塑密集层时出错

问题描述 投票:0回答:1

嗨,我想在 Dense 层之后重塑一个层,但它返回有趣的错误。这是代码

codings_size=10
decoder_inputs = tf.keras.layers.Input(shape=[codings_size])
# x=tf.keras.layers.Flatten(decoder_inputs)
x=tf.keras.layers.Dense(3 * 3 * 16)(decoder_inputs),
x=tf.keras.layers.Reshape((3, 3, 16))(x),

错误在这里

AttributeError: Exception encountered when calling layer "reshape_28" (type Reshape).

'tuple' object has no attribute 'shape'

Call arguments received by layer "reshape_28" (type Reshape):
  • inputs=('tf.Tensor(shape=(None, 144), dtype=float32)',)
python tensorflow keras deep-learning
1个回答
0
投票

错误是你添加了额外的逗号。只需删除它们。像这样:

codings_size=10
decoder_inputs = tf.keras.layers.Input(shape=[codings_size])
# x=tf.keras.layers.Flatten(decoder_inputs)
x=tf.keras.layers.Dense(3 * 3 * 16)(decoder_inputs)
x=tf.keras.layers.Reshape((3, 3, 16))(x)
© www.soinside.com 2019 - 2024. All rights reserved.