用tensorflow構建兩層簡單神經網絡(全連接)


中國大學Mooc 北京大學 人工智能實踐:Tensorflow筆記(week3)

#coding:utf-8
#兩層簡單神經網絡(全連接)

import tensorflow as tf

#定義輸入和參數
#用placeholder實現輸入定義(sess.run中喂一組數據)
x = tf.placeholder(tf.float32, shape = (None, 2))
w1 = tf.Variable(tf.random_normal([2, 3], stddev = 1, seed = 1))
w2 = tf.Variable(tf.random_normal([3, 1], stddev = 1, seed = 1))

#定義向前傳播過程
a = tf.matmul(x, w1)
y = tf.matmul(a, w2)


#用會話計算結果
with tf.Session() as sess:
    init_op = tf.global_variables_initializer()
    sess.run(init_op)
    print("the result of this exercise is \n", sess.run(y, feed_dict = {x:[[0.7, 0.5], [0.2, 0.3], [0.3, 0.4], [0.4, 0.5]]}))
    print("w1\n", sess.run(w1))
    print("w2\n", sess.run(w2))

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM