keras中的深度可分离卷积 SeparableConv2D与DepthwiseConv2D

【时间】2019.03.15

【题目】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 值可能已更改。

  • 9
    点赞
  • 92
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
Keras实现深度可分离卷积可以使用SeparableConv2D层。这个层实质上是将普通的卷积操作分解成两个步骤:深度方向的空间卷积(depthwise convolution)和逐点卷积(pointwise convolution)。首先,深度方向的空间卷积会分别作用于每个输入通道,然后将所得输出通道混合在一起。这个操作可以通过设置depth_multiplier参数来控制深度步骤每个输入通道生成多少个输出通道。接下来,我们可以使用一个1x1的卷积核对深度可分离卷积得到的输出进行常规卷积操作,得到最终的输出。在Keras,可以通过构建一个Sequential模型,并添加SeparableConv2D层来实现深度可分离卷积。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [Keras(二十)深度可分离卷积网络实战](https://blog.csdn.net/TFATS/article/details/114025123)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* [keras深度可分离卷积 SeparableConv2DDepthwiseConv2D](https://blog.csdn.net/C_chuxin/article/details/88581411)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值