tf.nn.depthwise_conv2d实现的深度卷积和普通的tf.nn.conv2d区别:
普通的卷积:
tf.nn.conv2d(input, filter, strides, padding, use_cudnn_on_gpu=None, name=None)
除去name参数用以指定该操作的name,与方法有关的一共五个参数:
input:
指需要做卷积的输入图像,它要求是一个Tensor,具有[batch, in_height, in_width, in_channels]这样的shape,具体含义是[训练时一个batch的图片数量, 图片高度, 图片宽度, 图像通道数],注意这是一个4维的Tensor,要求类型为float32和float64其中之一
filter:
相当于CNN中的卷积核,它要求是一个Tensor,具有[filter_height, filter_width, in_channels, out_channels]这样的shape,具体含义是[卷积核的高度,卷积核的宽度,图像通道数,卷积核个数],要求类型与参数input相同,有一个地方需要注意,第三维in_channels,就是参数input的第四维
strides:卷积时在图像每一维的步长,这是一个一维的向量,长度4
其为长度为4的一阶张量,并且要求strides[0]=strides[3]=1,strides[1],strides[2]决定卷积核在输入图像in_hight,in_width方向的滑动步长
padding:
string类型的量,只能是”SAME”,”VALID”其中之一,这个值决定了不同的卷积方式
use_cudnn_on_gpu:
bool类型,是否使用cudnn加速,默认为true
结果返回一个Tensor,这个输出,就是我们常说的feature map
最后feature map的个数为卷积核的个数
tf.nn.depthwise_conv2d实现深度卷积
tf.nn.depthwise_conv2d(input,filter,strides,padding,rate=None,name=None,data_format=None)
除去name参数用以指定该操作的name,data_format指定数据格式,与方法有关的一共五个参数:
input:
指需要做卷积的输入图像,要求是一个4维Tensor,具有[batch, height, width, in_channels]这样的shape,具体含义是[训练时一个batch的图片数量, 图片高度, 图片宽度, 图像通道数]
filter:
相当于CNN中的卷积核,要求是一个4维Tensor,具有[filter_height, filter_width, in_channels, channel_multiplier]这样的shape,具体含义是[卷积核的高度,卷积核的宽度,输入通道数,输出卷积乘子],同理这里第三维in_channels,就是参数value的第四维
strides:
卷积的滑动步长。
padding:
string类型的量,只能是”SAME”,”VALID”其中之一,这个值决定了不同边缘填充方式。
rate:
这个参数的详细解释见【Tensorflow】tf.nn.atrous_conv2d如何实现空洞卷积?
结果返回一个Tensor,shape为[batch, out_height, out_width, in_channels * channel_multiplier],注意这里输出通道变成了in_channels * channel_multiplier
最后输出的通道数为图片的通道数*卷积核的个数。
参考:https://blog.youkuaiyun.com/mao_xiao_feng/article/details/78003476