我想用python实现一个多尺度的CNN。我的目标是对三个不同的尺度使用三个不同的CNN,并将最终层的最终输出连接起来,并将它们提供给FC层以获得输出预测。
但我不明白该如何实现这一点。我知道如何实现单尺度CNN。
有人能在这方面帮我吗?
发布于 2018-08-26 04:11:35
我不明白为什么要有3个CNN,因为你会得到与单个CNN相同的结果。也许你可以训练得更快些。也许你也可以做一些池化和一些resnet操作(我猜这可能会被证明类似于你想要的)。
然而,对于每个CNN,你需要一个成本函数来优化你使用的“启发式”(例如:提高认知度)。同样,你也可以像在NN风格转移中那样做一些事情,你可以在几个“目标”(内容和风格矩阵)之间比较结果;或者简单地训练3个CNN,然后切断最后一层(或冻结它们),并使用已经训练好的权重再次训练,但现在使用目标FN层……
发布于 2019-04-03 17:16:48
这是一个多输入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 modelhttps://stackoverflow.com/questions/40329307
复制相似问题