zoukankan      html  css  js  c++  java
  • 吴裕雄--天生自然python Google深度学习框架:Tensorflow基础应用

     

     

     

     

     

     

     

     

     

    import tensorflow as tf
    
    a = tf.constant([1.0, 2.0], name="a")
    b = tf.constant([2.0, 3.0], name="b")
    result = a + b
    print(result)

     

     

     

     

     

    import tensorflow as tf
    
    g1 = tf.Graph()
    with g1.as_default():
        v = tf.get_variable("v", [1], initializer = tf.zeros_initializer()) # 设置初始值为0
    
    g2 = tf.Graph()
    with g2.as_default():
        v = tf.get_variable("v", [1], initializer = tf.ones_initializer())  # 设置初始值为1
        
    with tf.Session(graph = g1) as sess:
        tf.global_variables_initializer().run()
        with tf.variable_scope("", reuse=True):
            print(sess.run(tf.get_variable("v")))
    
    with tf.Session(graph = g2) as sess:
        tf.global_variables_initializer().run()
        with tf.variable_scope("", reuse=True):
            print(sess.run(tf.get_variable("v")))

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

    # 创建一个会话。
    sess = tf.Session()
    
    # 使用会话得到之前计算的结果。
    print(sess.run(result))
    
    # 关闭会话使得本次运行中使用到的资源可以被释放。
    sess.close()

    with tf.Session() as sess:
        print(sess.run(result))

     

     

    sess = tf.Session()
    with sess.as_default():
         print(result.eval())
    sess = tf.Session()
    
    # 下面的两个命令有相同的功能。
    print(sess.run(result))
    print(result.eval(session=sess))
    sess = tf.InteractiveSession ()
    print(result.eval())
    sess.close()

    config=tf.ConfigProto(allow_soft_placement=True, log_device_placement=True)
    sess1 = tf.InteractiveSession(config=config)
    sess2 = tf.Session(config=config)
  • 相关阅读:
    Docker 中 MySql 启动失败,报错 Can't open and lock privilege tables: Table storage engine for 'user'
    使用命令行编译和运行Java代码
    Linux编程--进程间通信
    Linux编程--信号
    HDU 2159 完全背包
    HDU 2844 多重背包
    hdu 2602 dp 01背包
    hdu 1864 01背包
    JSON学习
    Django Cookie
  • 原文地址:https://www.cnblogs.com/tszr/p/12049601.html
Copyright © 2011-2022 走看看