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()
运行结果:
文章来源:https://www.toymoban.com/news/detail-642476.html
文章来源地址https://www.toymoban.com/news/detail-642476.html
到了这里,关于测试 tensorflow 1.x 的一个demo 01的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!