A, tensorflow basis
Use TensorFlow, you must understand TensorFlow:
- FIG (Graph) to represent the computing tasks.
- In called
会话 (Session)
executes context (context) in the. - Represent data using tensor, tensor is a tensor, that is multi-dimensional arrays.
- By
变量 (Variable)
maintaining state. - Use can fetch and feed op (arbitrary operation) assigned any operation or from which data is acquired.
Summary: TensorFlow is a programming system, FIG computing tasks to represent nodes in the graph is called. Op (abbreviation of operation) to obtain a zero or more op. Tensor
, Perform calculations, generating zero or more Tensor.
Structure description:
- Session session may have a plurality of FIG graph, graph of FIG own default frame is generally used to FIG.
- FIG graph may have a plurality of operation op, op tensor can pass 0 or more incoming while outputting 0 or more tensor.
- That multidimensional array tensor, tensor can be Variable variable, constant lit, placeholeder placeholder, which will explain in three subsequent updates.
Sample code:
Import tensorflow TF AS # Create a constant variable, two constants, are two-dimensional array X = tf.Variable ([[l, 2,3], [4,5,6 ]]) W = tf.constant ([ [. 1], [2], [. 3 ]]) B = tf.constant ([[. 1], [. 1 ]]) # If a variable is defined, the operation executes before, to initialize variables, the following function initializes All variables the init = tf.global_variables_initializer () # the OP: matrix multiplication MATMUL = tf.matmul (X, W) # the OP: adding a matrix OP the Add = tf.add (MATMUL, B) # the OP: activation function OP RELU = tf.nn.relu (the Add) # create a session session, graph parameter is not specified the default map will be called Figure sess = tf.Session () sess.run (the init) # perform initialization print(sess.run (Relu)) # The final step in the implementation of map to run the entire map, layer by layer, the program will automatically forward calls sess.close () # session close # with With session is created, you can use you require use Close with TF the .session () AS sess: sess.run (the init) Print (sess.run (Relu))