tensorflow study notes (A) [basic concepts and constant usage]

Basic concepts of Tensorflow

Tensor means tensor, flow means flow, that is, data flow

  1. Use graphs to represent computing tasks
  2. Graphs are executed in a context called a Session
  3. Use tensor (tensor) to represent data
  4. Maintain state through variables (Variable)
  5. 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:
insert image description here
insert image description here
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:
insert image description here
Execution result:
insert image description here
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!

Guess you like

Origin blog.csdn.net/Cloud_1234_5678/article/details/89059013