zoukankan      html  css  js  c++  java
  • tf.nn.conv2d实现卷积的过程

    #coding=utf-8
    
    import tensorflow as tf
    #case 2
    input = tf.Variable(tf.round(10 * tf.random_normal([1,3,3,2])))
    filter = tf.Variable(tf.round(5 * tf.random_normal([1,1,2,1])))
    op2 = tf.nn.conv2d(input, filter, strides=[1, 1, 1, 1], padding='VALID')
    #对于filter,多个输入通道,变成一个输入通道,是对各个通道上的卷积值进行相加
    init = tf.global_variables_initializer()
    with tf.Session() as sess:
        sess.run(init)
        print("case 2")
        print("input: ", sess.run(input))
        print("filter: ", sess.run(filter))
        print("conv ", sess.run(op2))
    # case 2
    # input:  [[[[-14. -11.]
    #    [  2.   2.]
    #    [ 25.  18.]]
    #
    #   [[  8.  13.]
    #    [ -7.  -7.]
    #    [ 11.   6.]]
    #
    #   [[ -1.   8.]
    #    [ 18.  10.]
    #    [ -2.  19.]]]]
    # filter:  [[[[-3.]
    #    [ 2.]]]]
    
    # conv  [[[[ 20.]
    #    [ -2.]
    #    [-39.]]
    #
    #   [[  2.]
    #    [  7.]
    #    [-21.]]
    #
    #   [[ 19.]
    #    [-34.]
    #    [ 44.]]]]

     
    #转换:输入为3*3的2通道数据
    #通道1:
    #[-14 2 25],
    #[8 -7 11],
    #[-1 18 -2]
    #通道2:
    #[-11 2 18],
    #[13 -7 6],
    #[8 10 19]
    #conv转换
    #[20 -2 -39],
    #[2 -7 -21],
    #[9 -34 44]
    
    #计算过程
    #[-14 2 25],
    #[8 -7 11],  *  [-3]  +     
    #[-1 18 -2]
    #[-11 2 18],
    #[13 -7 6],  * [2]
    #[8 10 19]
    #result
    #[20 -2 -39],
    #[2 -7 -21],
    #[9 -34 44]
     
     
  • 相关阅读:
    python 安装包总结
    python wmi使用
    Jquery
    查看linux操作系统位数
    三元
    git clone 指定分支的内容
    慕课网
    http://amazeui.org 后天框架
    tp between
    git pull
  • 原文地址:https://www.cnblogs.com/adong7639/p/7598223.html
Copyright © 2011-2022 走看看