【发布时间】:2020-11-15 07:30:20
【问题描述】:
Keras 2.4.3 版
我正在创建一个简单的 Image-Caption 模型,它有两个输入和一个输出。
模型定义代码如下:
# Image feat part
imginp = Input(shape=(512,))
imglay1 = Dropout(0.5)(imginp)
imglay2 = Dense(EMBED_SIZE, activation=act)(imglay1)
# LSTM Part
textinp = Input(shape=(39,))
textlay1 = Embedding(VOCAB_SIZE, EMBED_SIZE, mask_zero=True)(textinp)
textlay2 = Dropout(0.5)(textlay1)
textlay3 = LSTM(EMBED_SIZE)(textlay2)
# # Decoder part that combines both
declay1 = Add()([imglay2, textlay3])
declay2 = Dense(EMBED_SIZE, activation=act)(declay1)
output = Dense(VOCAB_SIZE, activation="softmax")(declay2)
# Creating keras model
model = tf.keras.models.Model(inputs=[imginp,textinp],outputs=output)
model.summary()
然而,模型在model.fit() 上给出了一个错误,我注意到输入层给出了一个奇怪的输出,我认为这是导致错误的原因。 summary 的 sn-p 如下所示:
__________________________________________________________________________________________________
Layer (type) Output Shape Param # Connected to
==================================================================================================
input_82 (InputLayer) [(None, 39)] 0
__________________________________________________________________________________________________
input_81 (InputLayer) [(None, 512)] 0
__________________________________________________________________________________________________
embedding_31 (Embedding) (None, 39, 300) 511800 input_82[0][0]
__________________________________________________________________________________________________
dropout_79 (Dropout) (None, 512) 0 input_81[0][0]
正如您所见,输入层的输出形状需要(None, 512) 和(None, 39),但它们似乎是一个列表。因此,尽管我确实测试了 python 数据生成器,但我得到了 ValueError: no grad available for the variables。我相信这个Input layer api 会导致一些奇怪的错误。
有什么想法吗?
【问题讨论】:
标签: python tensorflow keras keras-layer tf.keras