zoukankan      html  css  js  c++  java
  • TensorFlow 学习(四)—— computation graph

    TensorFlow 的计算需要事先定义一个 computation graph(计算图),该图是一个抽象的结构,只有在评估(evaluate)时,才有数值解,这点和 numpy 不同。这张图由一组节点构成。

    >> a = tf.ones((2, 2))
    >> tf.reduce_sum(a, reduction_indices=1)
    <tf.Tensor 'Sum_2:0' shape=(2,) dtype=float32>
    >> tf.reduce_sum(a, reduction_indices=1).eval()
    array([ 2.,  2.], dtype=float32)

    0. 一个计算图实例



    relu = tf.nn.relu(tf.matmul(w, x) + b)

    1. TensorFlow 的计算机制

    TensorFlow 程序一般可划分为两个流程:

    • construction phase,构建过程,会构建出一个图(graph),即所谓的计算图(computation graph)
    • evaluation phase,执行过程,使用 session 执行构建过程中生成的图中的操作;

    2. placeholders:数据的读入

    tf.convert_to_tenso() 接口可将 numpy 下的多维数组转化为 tensor,但该函数接收的数据不可规模化。

    tf.placeholder() 提供了向计算图(computation graph)读入数据的入口点。

    feed_dict关键字参数,类型为 Python 的字典类型,实现了 tf.placeholder() 变量向数据(numpy arrays)的映射。

    >> input1 = tf.placeholder(tf.float32)
    >> input2 = tf.placeholder(tf.float32)
    >> output = tf.mul(input1, input2)
    >> with tf.Session() as sess:
            print(sess.run([output], feed_dict={input1: [7.], input2: [2.]}))

    3. tf.Graph() 图对象下的成员

    • get_operations():

      graph = tf.Graph()
      names = [op.name for op in model.graph.get_operations() if op.type=='Conv2D']
    • tensor = tf.get_default_graph().get_tensor_by_name(tensor_name)

      • Get the tensor with this name.
  • 相关阅读:
    金蝶数据库执行语句
    金蝶 更新价格分录表触发器
    金蝶触发器,生成条码信息
    SQL从中文中获取拼音首字母
    C语言 typedef用法
    这姑娘漂亮不,说实话,有糖吃
    条码开发的意义在哪里
    ERP开发,重点不在功能
    金蝶出入库数据库表里加字段后出现的问题解决
    解决金蝶未检测到K/3许可文件,并且该账套已超过演示版期限问题
  • 原文地址:https://www.cnblogs.com/mtcnn/p/9422024.html
Copyright © 2011-2022 走看看