TensorFlow from Beginner to Mastery (vii): TensorFlow operating principle

Source: Internet
Author: User

Through a few routines, we gradually established a perceptual knowledge of tensorflow. This article will further from the internal principle of deep understanding, and then for reading source to lay a good foundation.


1. Graph (graph)

The TensorFlow calculation is abstracted as a forward graph that includes several nodes. As shown in the example:

The corresponding TensorFlow Python code is as follows:

Import TensorFlow as TFB = tf. Variable ([Tf.zeros])                   # 100-d vector, init to ZEROESW = TF. Variable (Tf.random_uniform ([784,100],-1,1)) # 784x100 matrix W/rnd valsx = Tf.placeholder (name= "x") Relu = Tf.nn.relu ( Tf.matmul (W, x) + b) C = [...] s = tf. Session () For step in xrange (0, ten):  input = ... construct 100-d input array  ... result = S.run (C, feed_dict={x:input})  print step, result

In the TensorFlow graph, each node represents an operator and can have 0 or more inputs, 0 or more outputs.

The value of the flow of the normal edge of the graph (output from one node to the other) is called tensor (Tensor) and is essentially any dimension group. The element data type of the tensor can be explicitly specified or inferred when a map is constructed.

The figure and tensor of the implementation of the source code are located in tensorflow/tensorflow/python/framework/ops.py, we will talk about later.


2. Operation (Operations) and kernel function (kernels)

TensorFlow supports many common operations, such as matrix multiplication and addition.

A kernel function is a specific implementation of an operation that can be run on a particular type of device, such as a CPU or GPU.

The TensorFlow binary determines the supported set of operations and kernel functions through the registration mechanism, which can be further extended.

Table 1 shows some of the types of operations built into the TensorFlow


The operation-related code is in the following: tensorflow/tensorflow/python/ops/directory. Take the mathematical operation as an example, the code is math_ops.py in the above directory, call the gen_math_ops.py indirectly, and call the kernel function implementation of tensorflow/tensorflow/core/kernels/. We'll talk about that in the back.


3. Session (Sessions)

The client program interacts with the TensorFlow system by creating a session.

To create a calculation diagram, the session interface supports extension methods to complement the current diagram.

The Run interface allows you to specify that a tensor Tensor is fed into the calculation diagram as an ingress parameter, resulting in a set of computed outputs.

Session-related source code is located in tensorflow/tensorflow/python/client/session.py, we will be detailed in the following.



4. Variables (Variables)

In most calculations, a graph is executed more than once.

Most tensor lifecycles do not exceed the one-to-one execution of the graph.

A variable is a special operation that returns a continuously-changing tensor handle that spans multiple executions of the graph in the life cycle.

Variable handles can be passed to a number of special operations, such as Assign (=), assignadd (+ =).

For machine learning applications, model weights are typically stored in variables, and update operations are used as part of the train-to-graph Run.

Variable related source code is located in Tensorflow/tensorflow/python/ops/variables.py, is a kind of special operation. We'll talk about it later.

TensorFlow from Beginner to Mastery (vii): TensorFlow operating principle

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.