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

eqfvzcg8  于 2023-04-12  发布在  其他
关注(0)|答案(1)|浏览(143)

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

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)',)
kcrjzv8t

kcrjzv8t1#

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

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)

相关问题