小编Sat*_*Roy的帖子

层 lstm_5 的输入 0 与层不兼容:预期 ndim=3,发现 ndim=2

我正在尝试创建一个图像字幕模型。你能帮忙解决这个错误吗?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)

python nlp lstm keras tensorflow

8
推荐指数
1
解决办法
1801
查看次数

即使GenerateDocumentationFile 设置为 true,IDE0005 也不会报告为构建失败

如果存在未使用的用途,我希望项目的构建失败。在 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)

但是构建仍然没有失败。IDE 中报告错误,但构建成功。 在此输入图像描述

在此输入图像描述

有人可以让我知道我在这里缺少什么吗?我正在使用 Visual Studio 2022。

stylecop visual-studio editorconfig

7
推荐指数
0
解决办法
1178
查看次数

标签 统计

editorconfig ×1

keras ×1

lstm ×1

nlp ×1

python ×1

stylecop ×1

tensorflow ×1

visual-studio ×1