【问题标题】:Multiscale CNN - Keras Implementation多尺度 CNN - Keras 实现
【发布时间】:2017-03-12 18:37:54
【问题描述】:

我想在 python 中实现一个多尺度 CNN。我的目标是针对三个不同的尺度使用三个不同的 CNN,并将最终层的最终输出连接起来,并将它们馈送到 FC 层以进行输出预测。

但我不明白如何实现这一点。我知道如何实现单一规模的 CNN。

有人可以帮我吗?

【问题讨论】:

  • 你发现了吗?如果是,您能否将代码发布为答案?

标签: python neural-network concatenation convolution keras


【解决方案1】:

我不明白为什么要使用 3 个 CNN,因为与单个 CNN 相比,大多数情况下您会得到相同的结果。也许你可以训练得更快。 也许您还可以进行池化和一些 resnet 操作(我想这可能与您想要的相似)。

不过,对于每个 CNN,您都需要一个成本函数来优化您使用的“启发式”(例如:提高识别率)。此外,您可以在 NN Style Transfer 中做一些事情,在其中比较几个“目标”(内容和样式矩阵)之间的结果;或者只是训练 3 个 CNN,然后切断最后一层(或冻结它们)并使用已经训练过的权重再次训练,但现在使用您的目标 FN 层......

【讨论】:

    【解决方案2】:

    这是一个多输入 CNN 的示例。您只需引用提供每个网络输出的变量。然后使用连接并将它们传递到密集网络或您喜欢的任何任务中。

    def multires_CNN(filters, kernel_size, multires_data):
        '''uses Functional API for Keras 2.x support.
           multires data is output from load_standardized_multires()
        '''
        input_fullres = Input(multires_data[0].shape[1:], name = 'input_fullres')
        fullres_branch = Conv2D(filters, (kernel_size, kernel_size),
                         activation = LeakyReLU())(input_fullres)
        fullres_branch = MaxPooling2D(pool_size = (2,2))(fullres_branch)
        fullres_branch = BatchNormalization()(fullres_branch)
        fullres_branch = Flatten()(fullres_branch)
    
        input_medres = Input(multires_data[1].shape[1:], name = 'input_medres')
        medres_branch = Conv2D(filters, (kernel_size, kernel_size),
                         activation=LeakyReLU())(input_medres)
        medres_branch = MaxPooling2D(pool_size = (2,2))(medres_branch)
        medres_branch = BatchNormalization()(medres_branch)
        medres_branch = Flatten()(medres_branch)
    
        input_lowres = Input(multires_data[2].shape[1:], name = 'input_lowres')
        lowres_branch = Conv2D(filters, (kernel_size, kernel_size),
                         activation = LeakyReLU())(input_lowres)
        lowres_branch = MaxPooling2D(pool_size = (2,2))(lowres_branch)
        lowres_branch = BatchNormalization()(lowres_branch)
        lowres_branch = Flatten()(lowres_branch)
    
        merged_branches = concatenate([fullres_branch, medres_branch, lowres_branch])
        merged_branches = Dense(128, activation=LeakyReLU())(merged_branches)
        merged_branches = Dropout(0.5)(merged_branches)
        merged_branches = Dense(2,activation='linear')(merged_branches)
    
        model = Model(inputs=[input_fullres, input_medres ,input_lowres],
                      outputs=[merged_branches])
        model.compile(loss='mean_absolute_error', optimizer='adam')
    
        return model
    

    【讨论】:

      猜你喜欢
      • 2017-06-08
      • 2021-06-06
      • 2019-09-14
      • 2019-07-02
      • 1970-01-01
      • 1970-01-01
      • 2021-06-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多