Basic concepts of Tensorflow
Tensor means tensor, flow means flow, that is, data flow
- Use graphs to represent computing tasks
- Graphs are executed in a context called a Session
- Use tensor (tensor) to represent data
- Maintain state through variables (Variable)
- Use feed and fetch to assign values to or obtain data from arbitrary operations.
Tensorflow is a programming system that uses graphs to represent computing tasks. The nodes in graphs are called ops (operations), and one op obtains zero or more tensor, perform calculations (addition, subtraction, multiplication, division, etc.), and generate zero or more tensors. A tensor is viewed as an n-dimensional array or list. Graphs must be started in a Session.
Here is a sketch, you can have an intuitive impression.
Let's look at a program:
#用tf代表tensorflow,这样简写比较方便
import tensorflow as tf
#创建一个常量op
a = tf.constant("hello,")
#创建一个常量op
b = tf.constant("world.")
#创建一个加法op,把a,b相加
result = a + b
According to our habit, the result should be "hello, world." Let's run it to see:
Note that we only define a node now, but the graph must be started in the session:
add the following code and let's observe again:
Execution result:
we After starting the session, tensorflow has a default graph. Generally, we can use this default graph; three op, a, b, and result are triggered in the session.
Thank you!