tensorflow常见算子学习笔记(一):conv2d

  • Post author:
  • Post category:其他




函数说明



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



(1) conv2d参数说明

  • input: [batch, inputHeight, inputWidth, inputChannel]
  • filter: 卷积核,[filterHeight,filterWidth,filterChannel,filterNumber],

    inputChannel = filterChannel
  • strides: 步长,长度为4的一维向量,strides[0]=strides[3]=1,strides[1]表示行方向步长,strides[2]表示列方向步长,一般strides[1]=strides[2]
  • padding: 边界,“SAME”:补齐,“VALID”:舍弃

    补齐个数n:



    n

    =

    f

    i

    l

    t

    e

    r

    W

    i

    d

    t

    h

    (

    i

    n

    p

    u

    t

    W

    i

    d

    t

    h

    %

    s

    t

    r

    i

    d

    e

    s

    )

    n = filterWidth-(inputWidth\%strides)






    n




    =








    f


    i


    l


    t


    e


    r


    W


    i


    d


    t


    h













    (


    i


    n


    p


    u


    t


    W


    i


    d


    t


    h


    %


    s


    t


    r


    i


    d


    e


    s


    )






    舍弃个数n:



    n

    =

    i

    n

    p

    u

    t

    W

    i

    d

    t

    h

    f

    i

    l

    t

    e

    r

    W

    i

    d

    t

    h

    (

    i

    n

    p

    u

    t

    W

    i

    d

    t

    h

    s

    t

    r

    i

    d

    e

    1

    )

    s

    t

    r

    i

    d

    e

    n = inputWidth-filterWidth-(\left \lfloor \frac{inputWidth}{stride} \right \rfloor-1)*stride






    n




    =








    i


    n


    p


    u


    t


    W


    i


    d


    t


    h













    f


    i


    l


    t


    e


    r


    W


    i


    d


    t


    h













    (




















    s


    t


    r


    i


    d


    e
















    i


    n


    p


    u


    t


    W


    i


    d


    t


    h






































    1


    )













    s


    t


    r


    i


    d


    e




  • 其他参数:略



(2) 输出feature map shape计算

  • SMAE 模式




    • f

      e

      a

      t

      u

      r

      e

      M

      a

      p

      w

      i

      d

      t

      h

      =

      i

      n

      p

      u

      t

      W

      i

      d

      t

      h

      s

      t

      r

      i

      d

      e

      featureMapwidth = \left \lceil \frac{inputWidth}{stride} \right \rceil






      f


      e


      a


      t


      u


      r


      e


      M


      a


      p


      w


      i


      d


      t


      h




      =


























      s


      t


      r


      i


      d


      e
















      i


      n


      p


      u


      t


      W


      i


      d


      t


      h





























  • VAILD 模式




    • f

      e

      a

      t

      u

      r

      e

      M

      a

      p

      w

      i

      d

      t

      h

      =

      i

      n

      p

      u

      t

      W

      i

      d

      t

      h

      f

      i

      l

      t

      e

      r

      t

      W

      i

      d

      t

      h

      1

      s

      t

      r

      i

      d

      e

      featureMapwidth = \left \lceil \frac{inputWidth-filtertWidth-1}{stride} \right \rceil






      f


      e


      a


      t


      u


      r


      e


      M


      a


      p


      w


      i


      d


      t


      h




      =


























      s


      t


      r


      i


      d


      e
















      i


      n


      p


      u


      t


      W


      i


      d


      t


      h





      f


      i


      l


      t


      e


      r


      t


      W


      i


      d


      t


      h





      1





























  • 简单结论

    • stride = 1, 则 featureMapwidth = inputWidth,与其他参数无关



(3) 卷积的过程简易描述

inputShape:[1,227,227,

3

]

filterShape:[3,3,

3

,64]

inputTensor有3个通道,那么每个卷积核的深度也是3,卷积核的每个通道分别对接inputTensor的每个通道进行并行特征采集,然后求3个特征的采集数据值和作为该卷积核的特征采集结果。



(4) 一些基本概念

1.输入通道数=卷积核的深度(针对深度不分离卷积)

2.卷积核的个数=输出通道数

3.全连接才会加偏置,卷积不会,weight就是卷积核的参数承载

4.weight的shape[0],shape[1]就是卷积核的高与宽

5.输出feature map shape由pad模式,卷积核shape,stride3个参数共同决定;但是只有VALID模式下与卷积核形状有关系。



版权声明:本文为weixin_37997371原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。