中國大學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))