Getting Started With TensorFlow
TensorFlow provides multiple APIs.
TensorFlow Core
tf.contrib.learn
Tensors
A tensor consists of a set of primitive values shaped into an array of any number of dimensions.
Tensor's rank
TensorFlow Core programs consist of two discrete sections:
1,Building the computational graph
2,Running the computational graph
The Computational Graph
it is a series of TensorFlow operations arranged into a graph of nodes.
Graph Node
Each node takes zero or more tensors as inputs and produces a tensor as an output.
Session
A session encapsulates the control and state of the Tensorflow runtime.
TensorBoard
display a picture of the computational graph.
Placeholders
A placeholder is a promise to provide a value later.
Variables
add trainable parameters to a graph.
To initialize all the variables in a TensorFlow program, you must explicitly call a special operation as follows:
init = tf.global_variables_initializer()
sess.run(init)
Loss function
measures how far apart the current model is from the provided data.
tf.train API
Tensorflow provides optimizers that slowly change each variable in order to minimize the loss function.
In general, computing symbolic derivatives manually is tedious and error-prone. Consequently, TensorFlow can automativally produce derivatives given only a description of the model using the function tf.gradients.
optimizer=tf.train.GradientDescentOptimizer(0.01)
train=optimizer.minimize(loss);
gradient descent
It modifies each variable according to the magnitude of the derivative of loss with respect to that variable.
tf.contrib.learn
including:
running training loops
running evaluation loops
managing data sets
managing feeding
estimators:
linear regression
logistic regression
linear classification
logistic classification
neural network classifiers and regressors
A custom model
LinearRegressor is actually a sub-class of tf.contrib.learn.Estimator.
tf.contrib.learn Quickstart
Building Input Functions with tf.contrib.learn
Custom Input Pipelines with input_fn
It's possible to pass your feature and target data directly into your fit, evaluate, or predict operations.
TensorBoard: Visualizing Learning
TensorBoard operates by reading TensorFlow events files, which contain summary data that you can generate when running TensorFlow.
tf.summary.scalar & tf.summary.histogram
The summary nodes are peripheral to your graph
Use tf.summary.mergy_all to combine them into a single op that generates all the summary data.
tf.summary.FileWriter
网友评论