繁体   English   中英

是否可以创建同一个 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)

这个问题类似,我希望通过一个更大的 CNN(例如 XCeption 减去密集层)有几个图像输入层 go,然后将所有图像中的一个 CNN 的 output 连接成一个密集层。

在此处输入图像描述

Keras 是否可以做到这一点,或者甚至可以使用这种架构从头开始训练网络?

我本质上是想训练一个 model,它在每个样本中接收更大但固定数量的图像(即 3 个以上具有相似视觉特征的图像输入),但不要通过一次训练多个 CNN 来增加参数数量。 这个想法是只训练一个可用于所有输出的 CNN。 将所有图像 go 放入相同的密集层很重要,因此 model 可以学习跨多个图像的关联,这些关联始终根据其来源进行排序。

您可以通过以下方式使用 Keras 功能 API 轻松实现此目的。

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()```

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM