【问题标题】:Concatenating layers in Keras tensorflow2在 Keras tensorflow2 中连接层
【发布时间】:2020-05-29 03:46:44
【问题描述】:

我正在尝试在 keras tensorflow2 中连接图层:

initialinputs = Input(shape = (500, 4),name="sequences")

conv1d1 = Conv1D(hyperparameters['conv1_hidden_units'],
                activation='relu',
                kernel_size=hyperparameters['conv1_filter_size'],
                input_shape=(500, 4),
                padding='same')(initialinputs)
maxpool1 = MaxPooling1D(pool_size=hyperparameters['maxpool1_width'])(conv1d1)
dropout1 = Dropout(0.1)(maxpool1)
conv1d2 = Conv1D(hyperparameters['conv2_hidden_units'],
                activation='relu',
                kernel_size=hyperparameters['conv2_filter_size'],
                input_shape=(500, 4),
                padding='same')(dropout1)
maxpool2 = MaxPooling1D(pool_size=hyperparameters['maxpool2_width'])(conv1d2)
dropout2 = Dropout(0.1)(maxpool2)
conv1d3 = Conv1D(hyperparameters['conv3_hidden_units'],
                activation='relu',
                kernel_size=hyperparameters['conv3_filter_size'],
                input_shape=(500, 4),
                padding='same')(dropout2)
maxpool3 = MaxPooling1D(pool_size=hyperparameters['maxpool3_width'])(conv1d3)
dropout3 = Dropout(0.1)(maxpool3)
flatten = Flatten()(dropout3)

otherInp = Input(shape = (11,),name="coverage")
concatenatedFeatures = Concatenate(axis=1)([flatten, otherInp])

out = Dense(hyperparameters['num_classes'], activation='softmax')(concatenatedFeatures)

model = Model(inputs = [initialinputs, otherInp], outputs = out)

但我不断收到错误消息:

ValueError: Error when checking input: expected coverage to have shape (11,) but got array with shape (1,)

我认为我在这里缺少一些明显的东西,我已经在 StackOverflow 上进行了搜索,但似乎找不到解决方案。任何想法将不胜感激!

【问题讨论】:

  • 错误只是说你输入的形状不是预期值(1 vs 11),很难说为什么,你能解释为什么你的输入有形状(1,)而不是(11, )?
  • 反之亦然.....
  • 这是我不明白的部分,我想因为我指定了otherInp = Input(shape = (11,),name="coverage") ,所以它的形状是正确的。
  • 为 otherInp 运行 model.fit() 时的输入文件是 shape (11,7570),如果有帮助的话

标签: python keras concatenation tensorflow2.0 keras-layer


【解决方案1】:

我错误地加载了“otherInp”,因此它确实具有形状 (1,),已经更改了它并且它工作正常。感谢您的帮助!

【讨论】:

    猜你喜欢
    • 2020-03-28
    • 1970-01-01
    • 2022-01-20
    • 2017-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-21
    • 1970-01-01
    相关资源
    最近更新 更多