文章作者:Tyan
博客:noahsnail.com ?|? CSDN ?|? 簡(jiǎn)書
Introduction
Let's get you up and running with TensorFlow!
讓我們開(kāi)始學(xué)習(xí)并運(yùn)行TensorFlow!
But before we even get started, let's peek at what TensorFlow code looks like in the Python API, so you have a sense of where we're headed.
但在我們開(kāi)始之前,讓我們先看一眼在Python API中TensorFlow代碼什么樣,對(duì)我們要學(xué)習(xí)的東西有點(diǎn)感覺(jué)。
Here's a little Python program that makes up some data in two dimensions, and then fits a line to it.
下面是一個(gè)Python小程序,它在二維空間構(gòu)造了一些數(shù)據(jù),并用一條直線來(lái)擬合這些數(shù)據(jù)。
import tensorflow as tf
import numpy as np
# Create 100 phony x, y data points in NumPy, y = x * 0.1 + 0.3
x_data = np.random.rand(100).astype(np.float32)
y_data = x_data * 0.1 + 0.3
# Try to find values for W and b that compute y_data = W * x_data + b
# (We know that W should be 0.1 and b 0.3, but TensorFlow will
# figure that out for us.)
W = tf.Variable(tf.random_uniform([1], -1.0, 1.0))
b = tf.Variable(tf.zeros([1]))
y = W * x_data + b
# Minimize the mean squared errors.
loss = tf.reduce_mean(tf.square(y - y_data))
optimizer = tf.train.GradientDescentOptimizer(0.5)
train = optimizer.minimize(loss)
# Before starting, initialize the variables. We will 'run' this first.
init = tf.initialize_all_variables()
# Launch the graph.
sess = tf.Session()
sess.run(init)
# Fit the line.
for step in range(201):
sess.run(train)
if step % 20 == 0:
print(step, sess.run(W), sess.run(b))
# Learns best fit is W: [0.1], b: [0.3]
The first part of this code builds the data flow graph. TensorFlow does not actually run any computation until the session is created and the run function is called.
代碼的第一部分構(gòu)建數(shù)據(jù)流圖。在session創(chuàng)建和run函數(shù)調(diào)用之后,TensorFlow才開(kāi)始真正的進(jìn)行計(jì)算。
To whet your appetite further, we suggest you check out what a classical machine learning problem looks like in TensorFlow. In the land of neural networks the most "classic" classical problem is the MNIST handwritten digit classification. We offer two introductions here, one for machine learning newbies, and one for pros. If you've already trained dozens of MNIST models in other software packages, please take the red pill. If you've never even heard of MNIST, definitely take the blue pill. If you're somewhere in between, we suggest skimming blue, then red.
為了進(jìn)一步提高你的興趣,我們建議你查看一下在TensorFlow中經(jīng)典的機(jī)器學(xué)習(xí)問(wèn)題是什么樣子。在神經(jīng)網(wǎng)絡(luò)領(lǐng)域,最經(jīng)典的問(wèn)題是MNIST手寫字符識(shí)別問(wèn)題。這兒我們有兩個(gè)介紹,一個(gè)是為初學(xué)者準(zhǔn)備的,一個(gè)是為專業(yè)人士準(zhǔn)備的。如果你已經(jīng)用其它的軟件包訓(xùn)練了許多MNIST模型,請(qǐng)點(diǎn)紅色的藥丸。如果你從未聽(tīng)過(guò)MNIST,請(qǐng)點(diǎn)藍(lán)色藥丸。如果你介于兩者之間,我們建議你先略讀藍(lán)色部分,再看紅色部分。

圖像許可CC BY-SA 4.0; 原作者W. Carter
If you're already sure you want to learn and install TensorFlow you can skip these and charge ahead. Don't worry, you'll still get to see MNIST -- we'll also use MNIST as an example in our technical tutorial where we elaborate on TensorFlow features.
如果你已經(jīng)確定你想學(xué)習(xí)并安裝TensorFlow,你可以跳過(guò)這些直接看接下來(lái)的東西。不用擔(dān)心,你仍會(huì)看到MNIST——我們也將使用MNIST作為技術(shù)教程中的一個(gè)例子來(lái)闡述TensorFlow的特性。
