Google Cloud Platform / Tensorflow – MNIST

by allenlu2007

如何在 GCP 上 install Anaconda (python) and Tensorflow, 請參考前文。

參考: https://www.tensorflow.org/get_started/mnist/beginners

Machine learning 的標準例子就是 MNIST.  

下文是非常好的 MNIST blog

http://colah.github.io/posts/2014-10-Visualizing-MNIST/

 

Example 1:  Softmax Classifier

NewImage

NewImage

 

Step1: 先建 model.

MNIST 的 image 是 28×28=784 pixel (binary only? Or brightness?).  所以所有 image 是在 784-dimensional vector space. 最後要收歛到 10-dimension vector.   最簡單的是用 softmax classifier.  之後可以用 manifold learning?  (Known dimension reduction!)  

可以參考下文:

http://colah.github.io/posts/2014-10-Visualizing-MNIST/

我最欣賞幾何的詮釋:

It’s easy to slip into a mind set of thinking one of these techniques is better than the others, but I think they’re all complementary. There’s no way to map high-dimensional data into low dimensions and preserve all the structure. So, an approach must make trade-offs, sacrificing one property to preserve another. PCA tries to preserve linear structure, MDS tries to preserve global geometry, and t-SNE tries to preserve topology (neighborhood structure).

  

回到現實,最後要 train 出 W and b.   W 是 784×10.  b 是 10×1

 NewImage

NewImage

x 是 input vector (784, 1), y 是 output vector (10, 1) – one-hot.

Matmul: matrix multiplication. 

 

 

Step2: Training

Training data input 是 55K training image, 就是 55K x 784 (xs); output 是 55K x 10 (ys).

Test data 是 10K.  Validation data 是 5K.

NewImage

         NewImage

另外定義 loss function: cross-entropy loss

NewImage 

NewImage 

NewImage

NewImage

Use mini-batch of 100 images at a time.  

 

最後 train 出的 weights, W:

NewImage

最後的 test data:

NewImage

 

Example 2:  2 Convolution Layers + Softmax Classifier (softmax)

 NewImage

NewImage

最後是 99.2%.

Advertisements