zoukankan      html  css  js  c++  java
  • tensorflow 代码流程01

    阶段1:正常情况实现加法运算

    """
       __author__="dazhi"
        2021/3/5-12:35
    """
    import tensorflow as tf
    def tensorflow_demo():
        """tensorflow Basic structure"""
        a = 2
        b = 3
        c = a+b
        print("The result of addition ",c)
    
    if __name__=="__main__":
        tensorflow_demo()

    阶段2:在tensorflow的场景下实现加法运算

    """
       __author__="dazhi"
        2021/3/5-12:35
    """
    import tensorflow as tf
    import os
    os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
    def tensorflow_demo():
        tf.compat.v1.disable_eager_execution()
        #ensure sess.run () can operate normally
    
        """tensorflow Basic structure"""
        a = 2
        b = 3
        c = a+b
        print("The result of addition ",c)
    
        #tensorflow Realize addition operation
        a1 = tf.constant(2)
        b1 = tf.constant(3)
        c1 = a1+b1
        print("The result of addition ",c1)
        #Return call must be turned on to display results
        with tf.compat.v1.Session() as sess:
            c2 = sess.run(c1)
            print("The result of addition ", c2)
        return None
    
    
    
    if __name__=="__main__":
        tensorflow_demo()

     

    阶段3:默认图

    """
       __author__="dazhi"
        2021/3/5-12:35
    """
    import tensorflow as tf
    import os
    os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
    
    def graph_demo():
        tf.compat.v1.disable_eager_execution()
        #ensure sess.run () can operate normally
        """tensorflow Basic structure"""
        #tensorflow Realize addition operation
    
        a1 = tf.constant(2)
        b1 = tf.constant(3)
        c1 = a1+b1
        print("The result of addition ", c1)
    
        #View default map
        #Method 1: call the method
        default_g=tf.compat.v1.get_default_graph()
        print("default_g :",default_g)
    
        #Method 2: view properties
        print(" a1 Graph properties  ",a1.graph)
        print(" c1 Graph properties  ",c1.graph)
    
        #Return call must be turned on to display results
        with tf.compat.v1.Session() as sess:
            c2 = sess.run(c1)
            print("The result of addition ", c2)
            print("sess Graph properties ", sess.graph)
        return None
    
    
    
    if __name__=="__main__":
        graph_demo()

     

    阶段4:自定义图

    """
       __author__="dazhi"
        2021/3/5-12:35
    """
    import tensorflow as tf
    import os
    os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
    
    def graph_demo():
        tf.compat.v1.disable_eager_execution()
        #ensure sess.run () can operate normally
        """tensorflow Basic structure"""
        #tensorflow Realize addition operation
    
        #Custom map
        new_g=tf.Graph()
        with new_g.as_default():
            a1 = tf.constant(2)
            b1 = tf.constant(3)
            c1 = a1+b1
            print("The result of addition ", c1)
    
            #View default map
            #Method 1: call the method
            default_g=tf.compat.v1.get_default_graph()
            print("default_g :",default_g)
    
            #Method 2: view properties
            print(" a1 Graph properties  ",a1.graph)
            print(" c1 Graph properties  ",c1.graph)
    
        #Return call must be turned on to display results
        with tf.compat.v1.Session(graph=new_g) as sess:
            c2 = sess.run(c1)
            print("The result of addition ", c2)
            print("sess Graph properties ", sess.graph)
        return None
    
    
    
    if __name__=="__main__":
        graph_demo()

     

    阶段5:图结构的可视化

    """
       __author__="dazhi"
        2021/3/5-12:35
    """
    import tensorflow as tf
    import os
    os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
    
    def graph_demo():
        tf.compat.v1.disable_eager_execution()
        #ensure sess.run () can operate normally
        """tensorflow Basic structure"""
        #tensorflow Realize addition operation
    
        #Custom map
        new_g=tf.Graph()
        with new_g.as_default():
            a1 = tf.constant(2)
            b1 = tf.constant(3)
            c1 = a1+b1
    
        #Return call must be turned on to display results
        with tf.compat.v1.Session(graph=new_g) as sess:
            c2 = sess.run(c1)
            #Write the graph to the locally generated events file
            tf.compat.v1.summary.FileWriter("./tmp/summary",graph=sess.graph)
    
    
        return None
    
    
    
    if __name__=="__main__":
        graph_demo()

    阶段6:修改指令名称

    """
       __author__="dazhi"
        2021/3/5-12:35
    """
    import tensorflow as tf
    import os
    os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
    
    def graph_demo():
        tf.compat.v1.disable_eager_execution()
        #ensure sess.run () can operate normally
        """tensorflow Basic structure"""
        #tensorflow Realize addition operation
    
        #Custom map
        new_g=tf.Graph()
        with new_g.as_default():
            a1 = tf.constant(2,name="wen")
            b1 = tf.constant(3,name="xue")
            c1 = tf.add(a1,b1,name="zhi")
    
        #Return call must be turned on to display results
        with tf.compat.v1.Session(graph=new_g) as sess:
            c2 = sess.run(c1)
            #Write the graph to the locally generated events file
            tf.compat.v1.summary.FileWriter("./tmp/summary",graph=sess.graph)
    
    
        return None
    
    
    
    if __name__=="__main__":
        graph_demo()

    阶段7:placeholder操作

    """
       __author__="dazhi"
        2021/3/5-18:46
    """
    import tensorflow as tf
    import os
    os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
    
    def graph_demo():
        tf.compat.v1.disable_eager_execution()
        #ensure sess.run () can operate normally
        """tensorflow Basic structure"""
        #tensorflow Realize addition operation
    
        new_g=tf.Graph()
        with new_g.as_default():
            a1 = tf.compat.v1.placeholder(tf.float32)
            b1 = tf.compat.v1.placeholder(tf.float32)
            c1 = tf.add(a1,b1)
    
        #Return call must be turned on to display results
        with tf.compat.v1.Session(graph=new_g) as sess:
            #run placeholder
            c2 = sess.run(c1,feed_dict={a1:2,b1:23})
            print("The value of c2 ",c2)
    
        return None
    
    
    
    if __name__=="__main__":
        graph_demo()

  • 相关阅读:
    PL/SQL会遇到中文插入乱码问题、数据显示不全
    PL/SQL数据生成器
    编程小案例
    MySql案例收集
    关于PL/SQL的安装配置
    Android 歌词桌面同步显示
    DataGridView控件使用大全
    flex java 交互
    Android Launcher 全面剖析
    Android adb 命令
  • 原文地址:https://www.cnblogs.com/dazhi151/p/14486462.html
Copyright © 2011-2022 走看看