DepthwiseConv2D 类keras.layers.DepthwiseConv2D(
kernel_size,
strides=(1, 1),
padding="valid",
depth_multiplier=1,
data_format=None,
dilation_rate=(1, 1),
activation=None,
use_bias=True,
depthwise_initializer="glorot_uniform",
bias_initializer="zeros",
depthwise_regularizer=None,
bias_regularizer=None,
activity_regularizer=None,
depthwise_constraint=None,
bias_constraint=None,
**kwargs
)
2D 深度卷积层。
深度卷积是一种卷积类型,其中每个输入通道都与不同的核(称为深度核)进行卷积。你可以将深度卷积理解为深度可分离卷积的第一步。
它通过以下步骤实现:
depth_multiplier 输出通道的单独深度核进行卷积。与常规的 2D 卷积不同,深度卷积不会跨不同的输入通道混合信息。
depth_multiplier 参数决定了应用于每个输入通道的卷积核数量。因此,它控制了在深度卷积步骤中每个输入通道生成的输出通道的数量。
参数
strides > 1 与 dilation_rate > 1 不兼容。"valid" 或 "same"(不区分大小写)。"valid" 表示不填充。"same" 会在输入的左/右或上/下均匀填充。当 padding="same" 且 strides=1 时,输出与输入大小相同。input_channel * depth_multiplier。"channels_last" 或 "channels_first"。输入的维度顺序。"channels_last" 对应输入形状为 (batch, height, width, channels),而 "channels_first" 对应输入形状为 (batch, channels, height, width)。它默认为 Keras 配置文件 ~/.keras/keras.json 中的 image_data_format 值。如果您从未设置过,则默认为 "channels_last"。None,则不应用激活。True,则会将偏置添加到输出中。None,则使用默认初始化器("glorot_uniform")。None,将使用默认初始化器("zeros")。Optimizer 更新后对其进行应用(例如,用于实现层权重的范数约束或值约束)。该函数必须接受未投影变量作为输入,并返回投影后的变量(该变量的形状必须与输入相同)。在进行异步分布式训练时,使用约束是不安全的。Optimizer 更新偏置后应用于偏置。输入形状
data_format="channels_last":形状为 (batch_size, height, width, channels) 的 4D 张量data_format="channels_first":形状为 (batch_size, channels, height, width) 的 4D 张量输出形状
data_format="channels_last":一个 4D 张量,形状为:(batch_size, new_height, new_width, channels * depth_multiplier)data_format="channels_first":一个 4D 张量,形状为:(batch_size, channels * depth_multiplier, new_height, new_width)返回
一个 4D 张量,表示 activation(depthwise_conv2d(inputs, kernel) + bias)。
引发
strides > 1 和 dilation_rate > 1 都存在时。示例
>>> x = np.random.rand(4, 10, 10, 12)
>>> y = keras.layers.DepthwiseConv2D(kernel_size=3, activation='relu')(x)
>>> print(y.shape)
(4, 8, 8, 12)