【问题标题】:Keras ValueError: Dimensions must be equalKeras ValueError:尺寸必须相等
【发布时间】:2017-07-18 18:50:25
【问题描述】:

该模型的目标是通过与视频输入相关联的词对视频输入进行分类。每个输入的维度为 45 帧、1 个灰色通道、100 个像素行和 150 个像素列(45、1、100、150),而每个对应的输出是 3 个可能单词之一的一个热编码表示(例如“是" => [0, 0, 1])。

模型编译过程中,出现如下错误:

ValueError: Dimensions must be equal, but are 1 and 3 for 'Conv2D_94' (op: 'Conv2D') with 
input shapes: [?,100,150,1], [3,3,3,32].

这是用于训练模型的脚本:

video = Input(shape=(self.frames_per_sequence,
                     1,
                     self.rows,
                     self.columns))
cnn = InceptionV3(weights="imagenet",
                  include_top=False)
cnn.trainable = False
encoded_frames = TimeDistributed(cnn)(video)
encoded_vid = LSTM(256)(encoded_frames)
hidden_layer = Dense(output_dim=1024, activation="relu")(encoded_vid)
outputs = Dense(output_dim=class_count, activation="softmax")(hidden_layer)
osr = Model([video], outputs)
optimizer = Nadam(lr=0.002,
                  beta_1=0.9,
                  beta_2=0.999,
                  epsilon=1e-08,
                  schedule_decay=0.004)
osr.compile(loss="categorical_crossentropy",
            optimizer=optimizer,
            metrics=["categorical_accuracy"]) 

【问题讨论】:

  • @roganjosh 请查看更新后的问题。谢谢。
  • @roganjosh 你说删除回溯,所以我做了。
  • 您误读了该评论。我的意思是“发布格式正确的回溯而不是图像”。我想不出删除跟踪可以提供帮助的任何情况。它不应该是裁剪的图像。抱歉,如果不清楚。
  • @roganjosh 明白了。我已经更新了问题

标签: python machine-learning deep-learning keras


【解决方案1】:

根据 Keras 中的Convolution2D,下面应该是 input 和 filter 的形状。

shape of input = [batch, in_height, in_width, in_channels]
shape of filter = [filter_height, filter_width, in_channels, out_channels]

所以,你得到的错误的含义 -

ValueError: Dimensions must be equal, but are 1 and 3 for 'Conv2D_94' (op: 'Conv2D') with 
input shapes: [?,100,150,1], [3,3,3,32].

[?,100,150,1] 表示 in_channels 值为 1,而 [3,3,3,32] 表示 in_channels 值为 3。这就是您收到错误消息的原因 - Dimensions must be equal, but are 1 and 3

因此您可以将过滤器的形状更改为[3, 3, 1, 32]

【讨论】:

    猜你喜欢
    • 2021-11-08
    • 1970-01-01
    • 2021-08-29
    • 2019-10-11
    • 2022-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-18
    相关资源
    最近更新 更多