淘先锋技术网

首页 1 2 3 4 5 6 7

tensorflow 1.0的示例代码

demo_01.py

import tensorflow as tf
import os
os.environ['TF_CPP_MIN_LOG_LEVEL']='2'

def tf114_demo():
        a = 3
        b = 4
        c = a + b
        print("a + b in py =",c)
        a_t = tf.constant(3)
        b_t = tf.constant(4)
        c_t = a_t + b_t
        print("TensorFlow add a_t + b_t =", c_t)
        with tf.Session() as sess:
                c_t_value = sess.run(c_t)
                print("c_t_value= ", c_t_value)

        return None

def graph_demo():
        a_t = tf.constant(3)
        b_t = tf.constant(4)
        c_t = a_t + b_t
        print("TensorFlow add a_t + b_t =", c_t)
        default_g = tf.get_default_graph()
        print("default_g:\n",default_g)
        print("a_t g:", a_t.graph)
        print("c_t g:", c_t.graph)
        with tf.Session() as sess:
                c_t_value = sess.run(c_t)
                print("c_t_value= ", c_t_value)
                print("sess g:", sess.graph)
        return None



if __name__ == "__main__":
#       tf114_demo()
        graph_demo()

运行结果: