我正在尝试创建一个图像字幕模型。你能帮忙解决这个错误吗?input1 是图像向量,input2 是字幕序列。32 是字幕长度。我想将图像向量与序列的嵌入连接起来,然后将其提供给解码器模型。
def define_model(vocab_size, max_length):
input1 = Input(shape=(512,))
input1 = tf.keras.layers.RepeatVector(32)(input1)
print(input1.shape)
input2 = Input(shape=(max_length,))
e1 = Embedding(vocab_size, 512, mask_zero=True)(input2)
print(e1.shape)
dec1 = tf.concat([input1,e1], axis=2)
print(dec1.shape)
dec2 = LSTM(512)(dec1)
dec3 = LSTM(256)(dec2)
dec4 = Dropout(0.2)(dec3)
dec5 = Dense(256, activation="relu")(dec4)
output = Dense(vocab_size, activation="softmax")(dec5)
model = tf.keras.Model(inputs=[input1, input2], outputs=output)
model.compile(loss="categorical_crossentropy", optimizer="adam")
print(model.summary())
return model
Run Code Online (Sandbox Code Playgroud)
ValueError: Input 0 of layer lstm_5 is incompatible with the layer: expected ndim=3, found ndim=2. Full shape received: [None, 512]
Run Code Online (Sandbox Code Playgroud) 如果存在未使用的用途,我希望项目的构建失败。在 csproj 中我添加了:
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Run Code Online (Sandbox Code Playgroud)
按照https://github.com/dotnet/roslyn/issues/41640中提到的解决方案 在 .editorconfig 中我添加了:
dotnet_diagnostic.IDE0005.severity = error
Run Code Online (Sandbox Code Playgroud)
有人可以让我知道我在这里缺少什么吗?我正在使用 Visual Studio 2022。