是否可以创建同一CNN的多个实例,这些实例吸收多个图像并串联成一个密集层? (喀拉拉邦) [英] Is it possible to create multiple instances of the same CNN that take in multiple images and are concatenated into a dense layer? (keras)

查看:80
本文介绍了是否可以创建同一CNN的多个实例,这些实例吸收多个图像并串联成一个密集层? (喀拉拉邦)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

类似于此问题,我正在寻找几个图像输入层通过一个较大的CNN(例如,XCeption减去密集层),然后将一个CNN在所有图像上的输出串联到一个密集层中.

Similar to this question, I'm looking to have several image input layers that go through one larger CNN (e.g. XCeption minus dense layers), and then have the output of the one CNN across all images be concatenated into a dense layer.

使用Keras可以做到这一点,或者甚至可以使用这种体系结构从头开始训练网络吗?

Is this possible with Keras or is it even possible to train a network from the ground-up with this architecture?

我本质上是在寻找一种训练模型,该模型可以在每个样本中获取更大但固定数量的图像(即具有类似视觉特征的3个以上图像输入),但不希望通过一次训练多个CNN来爆炸参数数量.这个想法是只训练一个CNN,该CNN可用于所有输出.将所有图像放入相同的密集层非常重要,因此该模型可以了解多个图像之间的关联,这些关联始终根据其来源进行排序.

I'm essentially looking to train a model that takes in a larger but fixed number of images per sample (i.e. 3+ image inputs with similar visual features), but not to explode the number of parameters by training several CNNs at once. The idea is to train only one CNN, that can be used for all the outputs. Having all images go into the same dense layers is important so the model can learn the associations across multiple images, which are always ordered based on their source.

推荐答案

您可以通过以下方式使用Keras功能API轻松实现这一目标.

You can easily achieve this using the Keras functional API the following way.

from tensorflow.python.keras import layers, models, applications

# Multiple inputs
in1 = layers.Input(shape=(128,128,3))
in2 = layers.Input(shape=(128,128,3))
in3 = layers.Input(shape=(128,128,3))

# CNN output
cnn = applications.xception.Xception(include_top=False)


out1 = cnn(in1)
out2 = cnn(in2)
out3 = cnn(in3)

# Flattening the output for the dense layer
fout1 = layers.Flatten()(out1)
fout2 = layers.Flatten()(out2)
fout3 = layers.Flatten()(out3)

# Getting the dense output
dense = layers.Dense(100, activation='softmax')

dout1 = dense(fout1)
dout2 = dense(fout2)
dout3 = dense(fout3)

# Concatenating the final output
out = layers.Concatenate(axis=-1)([dout1, dout2, dout3])

# Creating the model
model = models.Model(inputs=[in1,in2,in3], outputs=out)
model.summary()```

这篇关于是否可以创建同一CNN的多个实例,这些实例吸收多个图像并串联成一个密集层? (喀拉拉邦)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆