【问题标题】:"ValueError: Graph disconnected: cannot obtain value for tensor KerasTensor" - Getting this error when i concatenate vgg16 base to my own FC layer“ValueError: Graph disconnected: cannot get value for tensor KerasTensor” - 当我将 vgg16 基础连接到我自己的 FC 层时出现此错误
【发布时间】:2021-06-24 22:05:48
【问题描述】:

我有这个模型,我将 vgg16 基本模型连接到 1 个 FC 层,然后是我的输出层。 这就是整个模型的样子。

如果我扩展 vgg16,我有这个:

我正在尝试使用功能 api 将模型输入作为我的输入和 2 个输出,第一个是“block5_conv3”层,第二个是模型输出 (dense_19)。

我的代码如下:-

model = Model(inputs=[clf.get_layer('vgg16').input],
  outputs = [clf.get_layer('vgg16').get_layer('block5_conv3').output, clf.output])

我收到以下错误:-

无法弄清楚我在这里做错了什么。

【问题讨论】:

    标签: python tensorflow machine-learning keras deep-learning


    【解决方案1】:

    您应该首先从您的VGG16 定义一个中间模型,该模型返回所有​​所需的输出(在您的情况下:block5_conv3 和最终输出)

    vgg16 = VGG16(input_shape=(96,96,3), weights='imagenet', include_top=False)
    extraction_model = Model(
        inputs = [vgg16.input],
        outputs = [vgg16.get_layer('block5_conv3').output, vgg16.output])
    

    然后您可以将其用作新架构中的标准特征提取器:

    inp = Input((96,96,3))
    block5_conv3, x =  extraction_model(inp)
    x = GlobalAveragePooling2D()(x)
    x = Dense(64)(x)
    x = Dropout(0.3)(x)
    x = BatchNormalization()(x)
    output = Dense(2, activation='softmax')(x)
    model = Model(inputs=inp, outputs=[block5_conv3, output])
    

    【讨论】:

      猜你喜欢
      • 2020-03-17
      • 1970-01-01
      • 2021-05-22
      • 1970-01-01
      • 2017-10-10
      • 1970-01-01
      • 1970-01-01
      • 2021-10-27
      • 1970-01-01
      相关资源
      最近更新 更多