tensorflow学习: 卷积函数

来源:互联网 发布:mysql string length 编辑:程序博客网 时间:2024/04/27 23:29

今天学习了tensorflow的卷积函数,做笔记如下:


 tf.nn.conv2d(input, filter, strides, padding, use_cudnn_on_gpu=None, name=None)

  参数:

      input:四维张量,[batch, in_height, in_width, in_channels]

      filter:[filter_height, filter_width, in_channels, out_channels]

       strides:[1,h_stride,v_stride,1],只需要修改中间两项水平垂直移动

       padding:"VALID"和"SAME"两种模式

      use_cudnn_on_gpu:一个可选布尔值,默认情况下是True

      name: (可选)为这个操作取一个名字

   输出:[batch, out_height, out_width, out_channels]

   作用:对一个四维的输入数据input 和四维的卷积核filter 进行操作,然后对输入数据进行一个二维的卷积操作,最后得到卷积之后的结果。个人理解就是把通道看成一个整体进行卷积。

个人理解假设输入的彩色图像长度为100,宽度为100,则尺寸为100x100x3。卷积核大小为5×5,输出特征映射(特征图)数为10。
在tf.nn.conv2d中,卷积核形状定义为[width,height,in_channels,out_channels]即 [5, 5 , 3,10]。图像上的卷积核的形状为5x5x3,并且在整个图像上卷积10次,以产生10个不同的特征图。

 tf.nn.depthwise_conv2d(input, filter, strides, padding, name=None)

  参数:

    input: [batch, in_height, in_width, in_channels]

    filter: [filter_height, filter_width, in_channels, channel_multiplier]

    strides:[1,h_stride,v_stride,1]

    padding:一个字符串,取值为SAME 或者 VALID

    use_cudnn_on_gpu: 一个可选布尔值,默认情况下是True

    name:(可选)为这个操作取一个名字

      输出[batch, out_height, out_width,in_channels * channel_multiplier]


  作用:depthwise_conv2d 函数将不同的卷积核独立的应用在in_channels 的每个通道上(从通道1 到通道 channel_multiplier ),然后把所以的结果进行汇总。最后输出通道的总数是in_channels * channel_multiplier。个人理解就是把输入通道分开,分别进行卷积,最后合并。

个人理解:假设输入的彩色图像长度为100,宽度为100,则尺寸为100x100x3。卷积核大小为5×5。在tf.nn.depthwise_conv2d中,卷积核形状为[width,height,in_channels,channel_multiplier]即[5,5,3,10]。现在输出的方式不同了,卷积形状为5x5x1,对输入图像的3个通道(特征图)分别卷积,则输入图像的每一个通道(特征图)会生成10特征图,最后合并,得到总共30个特征图。channel_multiplier会告诉你每个维度需要应用多少个不同的过滤器。


3 tf.nn.separable_conv2d(input, depthwise_filter, pointwise_filter, strides, padding, name=None)

  参数:

    input: [batch, in_height, in_width, in_channels]

              depthwise_filter:[filter_height,filter_width,in_channels,channel_multiplier]  其中,in_channels 的卷积 深度是 1。

              pointwise_filter:[1, 1, channel_multiplier * in_channels, out_channels]。其中,pointwise_filter 是在depthwise_filter 卷积之后的混合卷积。

              strides:[1,h_stride,v_stride,1],  只需要修改中间两项水平垂直移动

              padding:"VALID"和"SAME",  两种模式

              name:(可选)为这个操作取一个名字

        作用:tf.nn.separable_conv2d是利用几个分离的卷积核去做卷积。首先用depthwise_filter做卷积,效果与depthwise_conv2d相同,然后用1x1的卷积核pointwise_filter去做卷积。


   


参考文章:http://blog.csdn.net/u012436149/article/details/52890859?locationNum=8&fps=1