1 import tensorflow as tf 2 3 #creates the graph represented 4 x = tf.Variable(3, name='x') 5 y = tf.Variable(4, name='y') 6 f = x * x * y + y + 2 7 8 #open a tensorflow session and use it to initialize the variable and evaluate f. 9 init = tf.global_variables_initializer()#prepare the init node 10 with tf.Session() as sess: 11 init.run()#initalize all the node 12 result = f.eval() 13 14 sess = tf.InteractiveSession() 15 init.run() 16 result = f.eval() 17 print(result) 18 sess.close() 19 20 #judge x twice 21 w = tf.constant(3) 22 x = w + 2 23 y = x + 5 24 z = x * 3 25 26 with tf.Session() as sess: 27 print(y.eval()) 28 print(z.eval()) 29 sess.close() 30 31 #judge x once 32 with tf.Session() as sess: 33 y_val, z_val = sess.run([y,z]) 34 print(y_val) 35 print(z_val) 36 sess.close()
一个简单的tensorflow示例
猜你喜欢
转载自www.cnblogs.com/bigstrawberrywakaka/p/9321235.html
今日推荐
周排行