TensorFlow is the second generation of deep learning framework of Google company in November 2015 revenue, is an improved version of the first generation DistBelief framework.

TensorFlow supports Python and c/c++ language, can be calculated in CPU or GPU, support the use of virtualenv or docker.

publish definition of

in order to use tensorflow, we first need to import it to

 import tensorflow as tf

for symbolic variables, we create a new

 x = tf.placeholder (tf.float32, [None, 784]) 

in the X is not a specific value, is just a placeholder, behind we need formula with tensorflow, we will take it as a

input in the model. We need weights weight and biases bias, here is handled by Variable definition, Varia Ble can be in the process of modified

 tf.Variable (w = tf.zeros ([784, 10]) = tf.Variable (tf.zeros) B ([10])) 

in the new Variable at the same time, we initialize it, then

 y = tf.nn.softmax (tf.matmul (x, w) + B 

) so that we the successful implementation of the model of

our training we use cross-entropy as our cost function

H_{y'} (y) = -sum_i y'_i log (y_i)

y is a probability distribution we predicted, Y'is the probability distribution

true in order to achieve cross entropy, we need a new placeholder as correct answer

 y_ input 

= tf.placeholder (tf.float32, [None, 10]) cross_entropy = -tf.reducen_sum (y_ * tf.log

(y)) by gradient Drop to achieve optimization model of

 train_step = tf.train.GradientDescentOptimizer (learning_rate).Minimize (cross_entropy) 

we use this model before, the last thing we need to do is

 init (with) = tf.initialize_all_variables (tf.Session) as sess: sess.run (init) 

now, I can train the model 1000 times.

, for I in, up xrange (1000): batch_xs, batch_ys = mnist.train.next_batch (100) sess.run (train_step, feed_dict = {x: batch_xs, y_: batch_ys}) 

with random data of small batch is called the

model of random training score

first, we contrast between real y_ and model the number of Y

 correct_prediction the correct number (tf.ar = tf.equal Gmax (y, 1), tf.agrmax (y_, 1)) 

this will return a list of Boolean, such as [True, False, True, True]

 accuracy = tf.reduce_mean (tf.cast (correc_prediction, tf.float32) (print) sess.run (accuracy, feed_dict = {x: mnist.test.images, y_: minst.test.labels}) 

) finally through the above calculation accuracy of

to start using

TensorFlow is not a pure neural network framework, but the use of data analysis framework of.

TensorFlow using flow graph directed graph (graph) representation of a calculation task. The nodes of a graph called OPS (operations) said to the data processing, graph flow.

to describe the boundary data of the frame calculation process is composed of tensor processing flow. This is the source of the name of.

TensorFl TensorFlow Ow tensor tensor means that the tensor data. High dimensional array, numpy.ndarray said.

TensorFlow using the Session execution graph used in Python, using the Variable maintenance state.Tf.constant is only used as the output of the OPS,.

data source, we construct a

only two constant input, then a simple graph matrix multiplication


 from tensorflow import Session, device, constant, matmul 'build a only two constant input, then a simple graph matrix multiplication #:' if you don't use with (session) statement, the need to manually execute session.close (#with device). The equipment designated to perform calculations of equipment: # "/cpu:0" the CPU. # "/gpu:0": the first GPU machine, if any. # machine "/gpu:1": second GPU, with Session (as) and so on. Session: # create execution graph context with device ('/cpu:0'): mat1 = constant # designated operation equipment ([[3, 3]]) # creates a source node mat2 = constant ([[2], [2]]) product = matmul (mat1, mat2) # node pre specified node, create a graph result = session.run (product) print # perform calculations (result) 

all above is the

, want to help everyone to learn, I hope you will support a script.

This paper fixed link:http://www.script-home.com/detailed-explanation-of-the-python-guide-to-use-tensorflow.html | Script Home | +Copy Link

Article reprint please specify:Detailed explanation of the Python guide to use tensorflow | Script Home

You may also be interested in these articles!