zoukankan      html  css  js  c++  java
  • tensorflow:图(Graph)的核心数据结构与通用函数(Utility function)

    1. 图(Graph)的核心数据结构

    • tf.Graph.__init__:建立一个空图;
    • tf.Graph.as_default():一个将某图设置为默认图,并返回一个上下文管理器,常与 with 结构相搭配;

      g = tf.Graph()
      with g.as_default():
        # Define operations and tensors in `g`.
        c = tf.constant(30.0)
        assert c.graph is g
      
      c = tf.constant(4.0)
      assert c.graph is tf.get_default_graph()
    • tf.Graph.finalized:返回True,如果图被完成

      • tf.Graph.finalize():完成图的构建,即将其设置为只读模式
      if not tf.Graph.finalized:
          tf.Graph.finalize()
    • tf.Graph.control_dependencies(control_inputs):定义一个控制依赖,并返回一个上下文管理器,也常与 with 结构搭配;

      with g.control_dependencies([a, b, c]):
          ....
          d = …
          e = …
      
      
      # `d` 和 `e` 将在 `a`, `b`, 和`c`执行完之后运行.
      
      
      def my_func(pred, tensor):
          with tf.control_dependencies([pred]):
              # 乘法操作(op)创建在该上下文,所以被加入依赖控制中
              #执行完pred之后再执行matmul
              return tf.matmul(tensor, tensor)
    • tf.Graph.device(device_name_or_function):定义运行图所使用的设备,并返回一个上下文管理器

      with g.device('/gpu:0'): ...
      with g.device('/cpu:0'): ...
  • 相关阅读:
    webapi之fiddler头设置
    ios---setContentOffset
    webapi参数处理get过个参数
    socket网络编程
    logging模块
    configparser模块(拷贝)
    hashlib模块--摘要算法
    异常处理
    面向对象拓展
    反射
  • 原文地址:https://www.cnblogs.com/mtcnn/p/9421620.html
Copyright © 2011-2022 走看看