我需要一个卷积层,该卷积层可根据输入输出可变数量的通道。
conv2d(filters = variable_number)
答案 0 :(得分:0)
您是说要可变数量的通道,还是需要可变数量的过滤器?
因为通道和过滤器不同。通道代表图像的颜色(R,G,B或灰度),并且需要滤镜才能从图像中提取特征。
此外,请您说明一下为什么需要数量可变的过滤器或渠道,以便我们为您提供帮助。谢谢!
答案 1 :(得分:0)
根据输入的不同,一个模型不能具有不同数量的过滤器。该模型需要固定以下参数才能进行训练。
如果通道的数量不同,则模型架构会针对不同的输入而变化,因此上面列出的所有点都会受到影响。
您可以使用所有固定参数构建模型,然后根据输入将dropout
用于图层。但是同样地,辍学是一种正则化技术,简单地说,辍学是指在随机选择的某些神经元集的训练阶段忽略单位(即神经元)。 “忽略”是指在特定的向前或向后通过期间不考虑这些单位。
OR
最合适的解决方案是-
下面是一个示例-
from keras.models import Model
from keras.layers import Input, concatenate, Conv2D, ZeroPadding2D
from keras.optimizers import Adagrad
import tensorflow.keras.backend as K
import tensorflow as tf
input_img1 = Input(shape=(44,44,3))
x1 = Conv2D(3, (3, 3), activation='relu', padding='same')(input_img1)
input_img2 = Input(shape=(34,34,3))
x2 = Conv2D(3, (3, 3), activation='relu', padding='same')(input_img2)
# Zero Padding of 5 at the top, bottom, left and right side of an image tensor
x3 = ZeroPadding2D(padding = (5,5))(x2)
# Concatenate works as layers have same size output
x4 = concatenate([x1,x3])
output = Dense(18, activation='relu')(x4)
model = Model(inputs=[input_img1,input_img2], outputs=output)
model.summary()
输出-
Model: "model_22"
__________________________________________________________________________________________________
Layer (type) Output Shape Param # Connected to
==================================================================================================
input_91 (InputLayer) (None, 34, 34, 3) 0
__________________________________________________________________________________________________
input_90 (InputLayer) (None, 44, 44, 3) 0
__________________________________________________________________________________________________
conv2d_73 (Conv2D) (None, 34, 34, 3) 84 input_91[0][0]
__________________________________________________________________________________________________
conv2d_72 (Conv2D) (None, 44, 44, 3) 84 input_90[0][0]
__________________________________________________________________________________________________
zero_padding2d_14 (ZeroPadding2 (None, 44, 44, 3) 0 conv2d_73[0][0]
__________________________________________________________________________________________________
concatenate_30 (Concatenate) (None, 44, 44, 6) 0 conv2d_72[0][0]
zero_padding2d_14[0][0]
__________________________________________________________________________________________________
dense_47 (Dense) (None, 44, 44, 18) 126 concatenate_30[0][0]
==================================================================================================
Total params: 294
Trainable params: 294
Non-trainable params: 0
__________________________________________________________________________________________________
希望这可以回答您的问题。学习愉快。