Computing TensorFlow the process and name origin

Introduction:

TensorFlow inner frame has int, float, string data types, data types but directly calculates the Python is not feasible with the data type TensorFlow. First data conversion only for the data type in Python TensorFlow is, after the calculated result obtained by Tensorflow, and then taken out from TensorFlow FIG. Next, an example our experience matrix calculation process after the drawing data into the Python object, then the calculation results of FIG taken out, as follows:

import tensorflow as tf
# 定义Python中int类型二维矩阵
A = [[1, 2, 3],
     [4, 5, 6]]
B = [[1, 1], [1, 1], [1, 1]]

# 将Python类型数据A和B传入图中
A_tf = tf.constant(A, dtype=tf.float32, name="A")
B_tf = tf.constant(B, dtype=tf.float32, name="B")

# 构建图中的计算节点
C_tf = tf.matmul(A_tf, B_tf)

print(C_tf)

Output:

tf.Tensor(
[[ 6.  6.]
 [15. 15.]], shape=(2, 2), dtype=float32)

 

In the above code, Python 3-5 define the behavior of the two-dimensional array of type int A and B. 8-9 is a row of data into the data type Python FIG TensorFlow; line 12 is to create a computing node TensorFlow drawing, this input is TensorFlow compute nodes and FIG. A_tf B_tf. The first stopper 12 acts to FIG finished building, it is to be noted that this is not really perform matrix operations, but the input and matrix operations defined in Figure matrix calculation is completed.

Actually the last line is started, is removed from the drawing data C_tf in this line. This internal mechanism from TensorFlow Speaking in TensorFlow in all nodes are Tensor data objects, such as A_tf Tensor and B_tf are subject TensorFlow figures, objects C_tf Tensor is TensorFlow in FIG.

To this Tensor C_tf now the object is removed from the drawing, TensorFlow frame will automatically find all leaf nodes to C_tf path, the path and all compute nodes (i.e., a matrix calculation in the present embodiment) are executed until the end of the calculation, i.e., C_tf get results. As shown below. This is exactly the name origin TensorFlow framework, namely Tensor + Flow.

Published 105 original articles · won praise 17 · views 110 000 +

Guess you like

Origin blog.csdn.net/qq_38890412/article/details/104058562