在TensorFlow中的cnn卷积和池化的计算及参数详解

来源:互联网 发布:淘宝导航条两边颜色 编辑:程序博客网 时间:2024/06/05 20:43

在TensorFlow中的cnn卷积和池化的计算及参数详解


TensorFlow中的卷积一般是通过tf.nn.conv2d()函数实现的具体可以查看官网:https://www.tensorflow.org/api_docs/python/tf/nn/conv2d


TensorFlow中的池化有几种方式举个例子:通过tf.nn.max_pool函数实现的具体可以查看官网:https://www.tensorflow.org/api_docs/python/tf/nn/max_pool


下面只要讲解cnn卷积和池化的计算及参数(具体理论知识自己补充):

    '''  # 卷积:
           strides:第1,第4参数都为1,中间两个参数为卷积步幅,如:[1,1,1,1],[1,2,2,1]
                 1、使用VALID方式,feature map的尺寸为       (3,3,1,32)卷积权重
                 out_height = ceil(float(in_height - filter_height + 1) / float(strides[1])) (28-3+1) / 1 = 26,(28-3+1) / 2 = 13
                 out_width = ceil(float(in_width - filter_width + 1) / float(strides[2])) (28-3+1) / 1 = 26,(28-3+1) / 2 = 13
                 2、使用使用SAME方式,feature map的尺寸为     (3,3,1,32)卷积权重
                 out_height = ceil(float(in_height) / float(strides[1]))  28 / 1 = 28,28 / 2 = 14
                 out_width = ceil(float(in_width) / float(strides[2]))   28 / 1 = 28,28 / 2 = 14
            ceil:函数返回数字的上入整数
      # 池化:
            ksize:第1,第4参数都为1,中间两个参数为池化窗口的大小,如:[1,1,1,1],[1,2,2,1]
                  实验证明:对于实际的池化后的数据尺寸,ksize没有影响,只是计算的范围不同。            
            strides:第1,第4参数都为1,中间两个参数为池化窗口的步幅,如:[1,1,1,1],[1,2,2,1]
                  实验证明:对于实际的池化后的数据尺寸,strides产生影响,具体的计算方式和卷积中的strides相同。'''


实验代码:https://github.com/luohangtong/my_tensorflow_learn/blob/master/udacity/convolutions.py

有错误欢迎指正。





阅读全文
0 0
原创粉丝点击