我想在python中实现多尺度CNN。我的目标是将三种不同的CNN用于三种不同的比例,并连接最终层的最终输出,并将它们馈送到FC层以进行输出预测。
但我不明白我该如何实现这一点。我知道如何实现单一规模的CNN。
有人可以帮助我吗?
答案 0 :(得分:0)
我不明白为什么要拥有3个CNN,因为与单个CNN相比,您获得的结果大部分相同。也许您可以更快地训练。 也许您还可以进行池化和一些resnet操作(我想这可能证明与您想要的类似)。
尽管如此,对于每个CNN,您都需要一个成本函数,以便优化您使用的“启发式”(例如:提高识别度)。另外,您可以像在NN样式传输中一样进行操作,在该样式中您比较多个“目标”(内容和样式矩阵)之间的结果;或简单地训练3个CNN,然后截断最后一层(或冻结它们)并使用已经训练过的权重再次训练,但现在使用目标FN层...
答案 1 :(得分:0)
这里是多输入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