zoukankan      html  css  js  c++  java
  • 吴裕雄 python 神经网络——TensorFlow训练神经网络:卷积层、池化层样例

    import numpy as np
    import tensorflow as tf
    
    M = np.array([
            [[1],[-1],[0]],
            [[-1],[2],[1]],
            [[0],[2],[-2]]
        ])
    
    print("Matrix shape is: ",M.shape)

    filter_weight = tf.get_variable('weights', [2, 2, 1, 1], initializer = tf.constant_initializer([[1, -1],[0, 2]]))
    biases = tf.get_variable('biases', [1], initializer = tf.constant_initializer(1))
    M = np.asarray(M, dtype='float32')
    M = M.reshape(1, 3, 3, 1)
    x = tf.placeholder('float32', [1, None, None, 1])
    
    conv = tf.nn.conv2d(x, filter_weight, strides = [1, 2, 2, 1], padding = 'SAME')
    bias = tf.nn.bias_add(conv, biases)
    pool = tf.nn.avg_pool(x, ksize=[1, 2, 2, 1], strides=[1, 2, 2, 1], padding='SAME')
    with tf.Session() as sess:
        tf.global_variables_initializer().run()
        convoluted_M = sess.run(bias,feed_dict={x:M})
        pooled_M = sess.run(pool,feed_dict={x:M})
        print("convoluted_M: 
    ", convoluted_M)
        print("pooled_M: 
    ", pooled_M)

  • 相关阅读:
    Lotto--poj2245
    Avoid The Lakes--poj3620
    Fire Net--hdu1045
    变形课--hdu1181
    Apache Mina入门实例
    谈谈项目
    设计模式之装饰者模式
    linux下的权限控制
    centos 6.5 搭建JSP运行环境
    centos 6.5 搭建ftp服务器
  • 原文地址:https://www.cnblogs.com/tszr/p/10876480.html
Copyright © 2011-2022 走看看