TensorFlow design

TensorFlow design mainly in the following two aspects.


    (1) the definition of the diagram of FIG completely separated and

        We know that the programming mode is usually divided into imperative programming (imperative style programming) and symbolic programming (symbolic style programming). Imperative programming is programming in the usual sense we understand, easy to understand and debug conducted in accordance with the original logic. Symbolic programming optimization involves many embedded and not easily understood and debugging, but the operation speed is relatively improved. Conventional deep learning framework, Torch typical imperative, Caffe, MXNet programming mode using a method of mixing, and TensorFlow completely symbolic programming. Symbols calculated variables typically define, and to establish a data flow diagram, a predetermined relation between the calculated individual variables in the data flow diagram, a data flow graph necessary to finally compile, but this time is a data flow diagram shell child, there is no real data, only after the input operation need to put, to model the entire data stream is formed, thereby forming the output value.
        E.g:

t = 8 + 7
print("t:", t)

        The result is output:

t: 15

        TensorFlow in the node, the data flow graph, actually corresponds to an operation in TensorFlow API, not really to run, as follows:

import tensorflow as tf
t = tf.add(8, 9)
print(t) 

        The resulting output is:

Tensor("Add:0", shape=(), dtype=int32)

        This is because the above code is only defined an action, not actually running.

(2) computation involved should be placed TensorFlow FIG.

        TensorFlow operation involved in the drawing should be placed, and occurs only in the diagram of the session (session) in. After opening the session, the data can be used to fill nodes, calculates; after the session is closed, can not be calculated. Thus, the session provides an environment for running operation and Tensor evaluated.

import tensorflow as tf

# 创建图
a = tf.constant([1.0, 2.0])
b = tf.constant([3.0, 4.0])
c = a * b

# 创建会话
sess = tf.Session()

# 计算 c
print(sess.run(c))

# 关闭会话
sess.close()

        result:

[3. 8.]

ps: all taken from Li Jiaxuan of technical analysis and practical << TensorFlow >> chapter IV, section 4.2

Guess you like

Origin blog.csdn.net/a857553315/article/details/93376421