Basic concepts in tensorflow

This article is some personal understanding after reading the official documentation.

Official document address: https://www.tensorflow.org/versions/r0.12/get_started/basic_usage.html#basic-usage

 

Understanding of tensor and op

Nodes in the graph are called ops (short for operations). 
An op takes zero or more Tensors, performs some computation, and produces zero or more Tensors.

Analogy: A neuron has multiple inputs and one or more outputs. The OP here can be regarded as a neuron, and the tensor can be regarded as the input data.


In TensorFlow terminology, a Tensor is a typed multi-dimensional array.
For example, you can represent a mini-batch of images as a 4-D array of floating point numbers with dimensions [batch, height, width,channels].

Tensor is an array, and each array element is multi-dimensional, which is actually a matrix.

 

Stages of a TensorFlow program

TensorFlow programs are usually organized into a build phase and an execution phase. During the build phase, the execution steps of the op are described as a graph. During the execution phase, the ops in the execution graph are executed using the session.

Stage 1: How to build the graph?

1. Building a graph starts with creating an op. Some ops are created without input, such as Constant. Such ops are called source ops.
2. In python, op objects are created by op constructors (ops constructors). When the op constructor creates an op object, it can pass a source op as the input of the op object to be constructed.
3. After the op object is created by the op constructor, it is added to the graph as a node. The TensorFlow Python library has a default graph to which the op constructor can add nodes. This default graph is sufficient for many programs.

Summary: Because the graph is composed of op objects, the process of building a graph is actually the process of creating op objects, and the process of connecting these op objects (such as an op object as the input of another op object) .

Stage 2: After the graph is constructed, how to execute it?

1. Because the graph needs to be started in the session. So in order to start a graph, the first step is to create a session object.
2. If the graph is not specified when the sessoin object is created, the default graph is used.

 

Understanding of Variable

Variables are used to maintain state information during the execution of the graph.

The parameters in a statistical model are usually represented as a set of variables. For example, you can store the weights of a neural network as a tensor in some variable. During training, this tensor is updated by repeatedly running the training graph.

 

Understanding of feeds and fetches

You can assign values ​​to or get data from any op.

 

Understanding of tensor, Constants, and Variables

Tensors are stored in Constants or Variables. Just like data can be placed in constants and variables. Data placed in variables can be modified, while data placed in constants cannot be modified.

The constant op is also an op, but it is relatively simple.

Article source: https://www.cnblogs.com/tsiangleo/p/6145112.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324628063&siteId=291194637