这篇教程keras中的深度可分离卷积 SeparableConv2D与DepthwiseConv2D写得很实用,希望能帮到您。
keras中的深度可分离卷积 SeparableConv2D与DepthwiseConv2D
技术标签: keras SeparableConv2D DepthwiseConv2D
【题目】keras中的深度可分离卷积 SeparableConv2D与DepthwiseConv2D
概述
keras中的深度可分离卷积有SeparableConv2D与c两种,
其中SeparableConv2D实现整个深度分离卷积过程,即深度方向的空间卷积 (分别作用于每个输入通道)+ 输出通道混合在一起的逐点卷积,
而DepthwiseConv2D仅仅实现前半部分的空间卷积 (分别作用于每个输入通道)。
下面是keras中文文档的内容。
一、SeparableConv2D
keras.layers.SeparableConv2D(filters, kernel_size, strides=(1, 1), padding='valid', data_format=None, dilation_rate=(1, 1), depth_multiplier=1, activation=None, use_bias=True, depthwise_initializer='glorot_uniform', pointwise_initializer='glorot_uniform', bias_initializer='zeros', depthwise_regularizer=None, pointwise_regularizer=None, bias_regularizer=None, activity_regularizer=None, depthwise_constraint=None, pointwise_constraint=None, bias_constraint=None)
深度方向的可分离 2D 卷积。
可分离的卷积的操作包括,首先执行深度方向的空间卷积 (分别作用于每个输入通道),紧接一个将所得输出通道 混合在一起的逐点卷积。depth_multiplier 参数控 制深度步骤中每个输入通道生成多少个输出通道。
直观地说,可分离的卷积可以理解为一种将卷积核分解成 两个较小的卷积核的方法,或者作为 Inception 块的 一个极端版本。
参数
- filters: 整数,输出空间的维度 (即卷积中滤波器的输出数量)。
- kernel_size: 一个整数,或者 2 个整数表示的元组或列表, 指明 2D 卷积窗口的高度和宽度。 可以是一个整数,为所有空间维度指定相同的值。
- strides: 一个整数,或者 2 个整数表示的元组或列表, 指明卷积沿高度和宽度方向的步长。 可以是一个整数,为所有空间维度指定相同的值。 指定任何 stride 值 != 1 与指定
dilation_rate 值 != 1 两者不兼容。
- padding:
"valid" 或 "same" (大小写敏感)。
- data_format: 字符串,
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」。
- dilation_rate: 一个整数,或者 2 个整数表示的元组或列表, 为使用扩张(空洞)卷积指明扩张率。 目前,指定任何
dilation_rate 值 != 1 与指定任何 stride 值 != 1 两者不兼容。
- depth_multiplier: 每个输入通道的深度方向卷积输出通道的数量。 深度方向卷积输出通道的总数将等于
filterss_in * depth_multiplier 。
- activation: 要使用的**函数 (详见 activations)。 如果你不指定,则不使用**函数 (即线性**:
a(x) = x )。
- use_bias: 布尔值,该层是否使用偏置向量。
- depthwise_initializer: 运用到深度方向的核矩阵的初始化器 详见 initializers)。
- pointwise_initializer: 运用到逐点核矩阵的初始化器 (详见 initializers)。
- bias_initializer: 偏置向量的初始化器 (详见 initializers)。
- depthwise_regularizer: 运用到深度方向的核矩阵的正则化函数 (详见 regularizer)。
- pointwise_regularizer: 运用到逐点核矩阵的正则化函数 (详见 regularizer)。
- bias_regularizer: 运用到偏置向量的正则化函数 (详见 regularizer)。
- activity_regularizer: 运用到层输出(它的**值)的正则化函数 (详见 regularizer)。
- depthwise_constraint: 运用到深度方向的核矩阵的约束函数 (详见 constraints)。
- pointwise_constraint: 运用到逐点核矩阵的约束函数 (详见 constraints)。
- bias_constraint: 运用到偏置向量的约束函数 (详见 constraints)。
输入尺寸
- 如果 data_format='channels_first', 输入 4D 张量,尺寸为
(batch, channels, rows, cols) 。
- 如果 data_format='channels_last', 输入 4D 张量,尺寸为
(batch, rows, cols, channels) 。
输出尺寸
- 如果 data_format='channels_first', 输出 4D 张量,尺寸为
(batch, filters, new_rows, new_cols) 。
- 如果 data_format='channels_last', 输出 4D 张量,尺寸为
(batch, new_rows, new_cols, filters) 。
由于填充的原因, rows 和 cols 值可能已更改。
二、DepthwiseConv2D
keras.layers.DepthwiseConv2D(kernel_size, strides=(1, 1), padding='valid', depth_multiplier=1, data_format=None, 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)
深度可分离 2D 卷积。
深度可分离卷积包括仅执行深度空间卷积中的第一步(其分别作用于每个输入通道)。 depth_multiplier 参数控制深度步骤中每个输入通道生成多少个输出通道。
Arguments
- kernel_size: 一个整数,或者 2 个整数表示的元组或列表, 指明 2D 卷积窗口的高度和宽度。 可以是一个整数,为所有空间维度指定相同的值。
- strides: 一个整数,或者 2 个整数表示的元组或列表, 指明卷积沿高度和宽度方向的步长。 可以是一个整数,为所有空间维度指定相同的值。 指定任何 stride 值 != 1 与指定
dilation_rate 值 != 1 两者不兼容。
- padding:
"valid" 或 "same" (大小写敏感)。
- depth_multiplier: 每个输入通道的深度方向卷积输出通道的数量。 深度方向卷积输出通道的总数将等于
filterss_in * depth_multiplier 。
- data_format: 字符串,
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」。
- activation: 要使用的**函数 (详见 activations)。 如果你不指定,则不使用**函数 (即线性**:
a(x) = x )。
- use_bias: 布尔值,该层是否使用偏置向量。
- depthwise_initializer: 运用到深度方向的核矩阵的初始化器 详见 initializers)。
- bias_initializer: 偏置向量的初始化器 (详见 initializers)。
- depthwise_regularizer: 运用到深度方向的核矩阵的正则化函数 (详见 regularizer)。
- bias_regularizer: 运用到偏置向量的正则化函数 (详见 regularizer)。
- activity_regularizer: 运用到层输出(它的**值)的正则化函数 (详见 regularizer)。
- depthwise_constraint: 运用到深度方向的核矩阵的约束函数 (详见 constraints)。
- bias_constraint: 运用到偏置向量的约束函数 (详见 constraints)。
输入尺寸
- 如果 data_format='channels_first', 输入 4D 张量,尺寸为
(batch, channels, rows, cols) 。
- 如果 data_format='channels_last', 输入 4D 张量,尺寸为
(batch, rows, cols, channels) 。
输出尺寸
- 如果 data_format='channels_first', 输出 4D 张量,尺寸为
(batch, filters, new_rows, new_cols) 。
- 如果 data_format='channels_last', 输出 4D 张量,尺寸为
(batch, new_rows, new_cols, filters) 。
由于填充的原因, rows 和 cols 值可能已更改。 返回列表 基于VGG16的可视化类激活的热力图(keras实现) |