計(jì)算圖:Graph
節(jié)點(diǎn):Node —— 運(yùn)算:Operation
邊:Edge 數(shù)據(jù):Tensor —— 流:Flow
標(biāo)量:
向量:
矩陣:
神經(jīng)網(wǎng)絡(luò):
會(huì)話:Session
變量:Variable
Client缀去、Master、Worker甸祭、Device->Allocator->Tensor
SoftMax Regression
reduction_indecies???
============
from tensorflow.examples.tutorials.mnist import input_data
import tensorflow as tf
#下載數(shù)據(jù)
mnist=input_data.read_data_sets("MNIST_data/",one_hot=True)
#查看數(shù)據(jù)緯度
print(mnist.train.images.shape,mnist.train.labels.shape)
print(mnist.test.images.shape,mnist.test.labels.shape)
print(mnist.validation.images.shape,mnist.validation.labels.shape)
sess=tf.InteractiveSession()
x=tf.placeholder(tf.float32,[None,784])
W=tf.Variable(tf.zeros([784,10]))
b=tf.Variable(tf.zeros([10]))
y=tf.nn.softmax(tf.matmul(x,W)+b)
y_=tf.placeholder(tf.float32,[None,10])
#交叉熵
cross_entropy=tf.reduce_mean(-tf.reduce_sum(y_*tf.log(y),reduction_indices=[1]))
#訓(xùn)練
train_step=tf.train.GradientDescentOptimizer(0.5).minimize(cross_entropy)
#變量初始化
tf.global_variables_initializer().run()
#載入訓(xùn)練數(shù)據(jù)開(kāi)始訓(xùn)練
for i in range(1000):
batch_xs,batch_ys=mnist.train.next_batch(100)
train_step.run({x:batch_xs,y_:batch_ys})
#準(zhǔn)確率計(jì)算公式
correct_prediction=tf.equal(tf.argmax(y,1),tf.argmax(y_,1))
accuracy=tf.reduce_mean(tf.cast(correct_prediction,tf.float32))
#在測(cè)試數(shù)據(jù)集上計(jì)算準(zhǔn)確率
print(accuracy.eval({x:mnist.test.images,y_:mnist.test.labels}))