Intro to Keras
John Ramey
@ramhiser
About Me
• Principal Data Scientist @
Novi Labs
• Stats + CS Background
• Soccer!
My Goal Tonight
• Introduce you to Keras
• Not teach you all of Keras
• But make damn sure that you can use Keras
Keras: Deep Learning Library
• High-level neural networks API, written in Python
• Models described in Python code. No separate models
config files
• Allows for easy and fast prototyping (through user
friendliness, modularity, and extensibility)
• Runs seamlessly on CPUs and GPUs
Keras: Backends
•TensorFlow, Theano, CNTK (Microsoft)
•Can deploy in production via TensorFlow Serving
Source: https://keras.io/#guiding-principles
Keras is an API designed for human beings, not
machines. It puts user experience front and center.
Keras follows best practices for reducing cognitive
load: it offers consistent & simple APIs, it minimizes
the number of user actions required for common use
cases, and it provides clear and actionable feedback
upon user error.
Really. That’s it.
pip install keras
How to Install Keras
import tensorflow.contrib.keras
Another Way
•Keras was rebuilt from the ground up for better TF integration
•Can take advantage of TF’s power and flexibility
•Will be import tensorflow.keras soon (TF 1.3?)
Also, Docker
Demo: TensorFlow +
Keras Docker Image
https://github.com/ramhiser/Keras-Tutorials
MNIST: The Hello, World of
Deep Learning
MNIST: The Hello, World of
Deep Learning
MNIST: Training
( , 2), ( , 8)
…
MNIST: Test
( , ?)
1st Model: Logistic
Regression
Source: https://stackoverflow.com/q/40537503/234233
Features Weights
2
Target
Goal: Learn “best” weights
1st Model: Logistic
Regression
Source: https://stackoverflow.com/q/40537503/234233
Features Weights
2
Target
Activation Function (nonlinear)
Demo
https://github.com/ramhiser/Keras-
Tutorials/blob/master/notebooks/02_logistic_regression.ipynb
2nd Model: Multilayer
Perceptron
2W11
W21
W1p W2p
Features 1st Weights 2nd Weights Target
Demo
https://github.com/ramhiser/Keras-
Tutorials/blob/master/notebooks/03_multilayer_perceptron.ipynb
3rd Model: Convolutional
Neural Net
Convolution
Image
Filter
Matrix
Stride = 1
Pad = 0
Convolution
Source: https://ujjwalkarn.me/2016/08/11/intuitive-explanation-
convnets/
Max Pooling
Source: http://www.wildml.com/2015/11/understanding-convolutional-
neural-networks-for-nlp/
Demo
https://github.com/ramhiser/Keras-
Tutorials/blob/master/notebooks/05_convolutional_neural_net.ipynb
Loads More Examples
Source: https://github.com/fchollet/keras/tree/master/examples
Lots of Pre-Trained Models
Source:
https://github.com/fchollet/keras/tree/master/keras/applications
Inception (v3)
Check This Out
Thank You!

Introduction to Keras