【问题标题】:Keras - adding a layer in front of a modelKeras - 在模型前面添加一层
【发布时间】:2017-08-10 22:56:36
【问题描述】:

我要做的是在导入的 VGG16 模型前面添加一个 Upsampling2D 层。但是我不知道怎么做,从来没有在互联网上的任何地方看到过这样的事情。

我想做什么:

VGG = VGG16()
model = Sequential()
model.add(UpSampling2D((32,32), input_shape=(7,7,3)))
model.add(VGG)

但是,尝试将此模型用于任何事情都会引发以下错误:

AttributeError: 层 model_1 有多个入站节点,因此“层输出”的概念定义不明确。请改用get_output_at(node_index)

知道为什么吗?

【问题讨论】:

    标签: keras


    【解决方案1】:

    您可以在VGG16() 中提供input_tensor 参数。

    from keras.applications.vgg16 import VGG16
    from keras.layers import Input, UpSampling2D
    input_tensor = Input(shape=(7, 7, 3))
    upsampled = UpSampling2D((32, 32))(input_tensor)
    VGG = VGG16(input_tensor=upsampled)
    

    通过运行VGG.summary(),您应该会看到如下内容:

    _________________________________________________________________
    Layer (type)                 Output Shape              Param # 
    =================================================================
    input_1 (InputLayer)         (None, 7, 7, 3)           0
    _________________________________________________________________
    up_sampling2d_1 (UpSampling2 (None, 224, 224, 3)       0
    _________________________________________________________________
    block1_conv1 (Conv2D)        (None, 224, 224, 64)      1792
    _________________________________________________________________
    block1_conv2 (Conv2D)        (None, 224, 224, 64)      36928
    _________________________________________________________________
    block1_pool (MaxPooling2D)   (None, 112, 112, 64)      0
    _________________________________________________________________
    
    ...
    

    【讨论】:

      猜你喜欢
      • 2020-11-13
      • 2023-03-12
      • 1970-01-01
      • 2023-03-08
      • 2017-07-27
      • 1970-01-01
      • 1970-01-01
      • 2017-04-17
      • 2017-06-13
      相关资源
      最近更新 更多