Tutorial (II) : Image Recognition Using TensorFlow
1
• Course: Digital Image Processing (ELEC4245)• Tutor: Dong Jinping (CB206, [email protected])• Venue: CB103• Date: 18 Apr, 2017
Outline
• Introduction of TensorFlow
• Image Recognition• Example on MNIST dataset
• Practice on CIFAR-10 dataset
• Summary
2
Introduction of TensorFlow
• TensorFlow1
• Open-source software for Machine Intelligence
• AlphaGo
• Installation on Windows2
• Installing with Anaconda (Python 3.5.x)
• Validate installation• valdt_instal.py
• Spyder• Scientific Python Development EnviRonment
3
1. https://www.tensorflow.org/2. https://www.tensorflow.org/install/install_windows3. Image from: http://www.cw.com.tw/article/article.action?id=5075965
3
Introduction of TensorFlow• Central unit of data: tensor
• A tensor's rank is its number of dimensions.
• Computational Graph (CG)• Build the CG• Run the CG
• cg_1.py• cg_2.py
• TensorBoard1
• Easier to understand, debug, optimize• Event file → Visualization
• tensorboard --logdir=logs• http://localhost:6006• tensorboard_example.py
41. https://www.tensorflow.org/get_started/graph_viz
3 ∗ 𝑎 + 𝑏 CG
Node
Image Recognition-Example• MNIST dataset of handwritten digits1
• 55,000 data points of training data (mnist.train)
• 10,000 points of test data (mnist.test)
• 5,000 points of validation data (mnist.validation)
• Every MNIST data point• An image of a handwritten digit, its corresponding label
51. http://yann.lecun.com/exdb/mnist/
5 0 4 1
Images
Labels
Image Recognition-Example
• MNIST dataset of handwritten digits1
• Each image is 28 pixels by 28 pixels. We can interpret this as a big array of numbers
• mnist.train.images is a tensor with a shape of [55000, 784]
• mnist.train.labels [55000, 10]
• mnist_example.py
61. http://yann.lecun.com/exdb/mnist/
Image Recognition-Example
• Softmax Regression1
• Add up the evidence of the input being in certain classes
• Convert that evidence into probabilities
71. https://www.tensorflow.org/get_started/mnist/beginners
Image Recognition-Example
• Image Recognition on MNIST1
• Softmax, Cross-entropy, Gradient descent (for more2),
• Build, Train and Evaluate the model
• Img_rcg_example.py
81. http://yann.lecun.com/exdb/mnist/2. https://www.tensorflow.org/api_guides/python/train#optimizers
Image Recognition-Example
• Results1
• Accuracy varies each time you run the code• ~92%
• Good or not?• Random guess: 10% ☺
• Current best model: 99.7%
• What if more training steps?• 1000 → 2000 → 3000
91. https://www.tensorflow.org/get_started/mnist/beginners
CG of this model
Image Recognition-Practice• CIFAR-10 dataset1
• Classify RGB 32x32 pixel images across 10 categories
• You need to do • Learn the functions used in Img_rcg_example.py
• ? / help() / https://www.tensorflow.org/api_docs/python/• Write Img_rcg_mine.py
• Similar procedure(build, train and evaluate the model)• Load CIFAR-10 using data_helpers.py2
• import data_helpers• data_sets = data_helpers.load_data()
• Use ‘loss function’• Satisfied accuracy? Why?• How to do better? One layer → Two layer?• Other optimizer?
• Answer code• Img_rcg_practice.py2
101. http://www.cs.toronto.edu/~kriz/cifar.html2. https://github.com/wolfib/image-classification-CIFAR10-tf
CIFAR-10
Summary
• Simple examples about Image Recognition using Machine Learning• MNIST
• CIFAR-10
• How TensorFlow works
• Core concepts about Machine Learning
• Need more efforts to learn this topic deeply
• To learn more• https://www.tensorflow.org/tutorials/mandelbrot
11
Thank you!
12