Mobile, AI and Tensorflow Lite - Developer Summit · Mobile, AI and Tensorflow Lite Supriya...

37

Transcript of Mobile, AI and Tensorflow Lite - Developer Summit · Mobile, AI and Tensorflow Lite Supriya...

Page 1: Mobile, AI and Tensorflow Lite - Developer Summit · Mobile, AI and Tensorflow Lite Supriya Srivatsa . NEURAL NETWORKS Human anatomy inspired learning network. Neural Networks . Neural
Page 2: Mobile, AI and Tensorflow Lite - Developer Summit · Mobile, AI and Tensorflow Lite Supriya Srivatsa . NEURAL NETWORKS Human anatomy inspired learning network. Neural Networks . Neural

Mobile, AI and Tensorflow Lite Supriya Srivatsa

Page 3: Mobile, AI and Tensorflow Lite - Developer Summit · Mobile, AI and Tensorflow Lite Supriya Srivatsa . NEURAL NETWORKS Human anatomy inspired learning network. Neural Networks . Neural
Page 4: Mobile, AI and Tensorflow Lite - Developer Summit · Mobile, AI and Tensorflow Lite Supriya Srivatsa . NEURAL NETWORKS Human anatomy inspired learning network. Neural Networks . Neural
Page 5: Mobile, AI and Tensorflow Lite - Developer Summit · Mobile, AI and Tensorflow Lite Supriya Srivatsa . NEURAL NETWORKS Human anatomy inspired learning network. Neural Networks . Neural

NEURAL NETWORKS

Human anatomy inspired learning network.

Page 6: Mobile, AI and Tensorflow Lite - Developer Summit · Mobile, AI and Tensorflow Lite Supriya Srivatsa . NEURAL NETWORKS Human anatomy inspired learning network. Neural Networks . Neural

Neural Networks

Page 7: Mobile, AI and Tensorflow Lite - Developer Summit · Mobile, AI and Tensorflow Lite Supriya Srivatsa . NEURAL NETWORKS Human anatomy inspired learning network. Neural Networks . Neural

Neural Networks

Page 8: Mobile, AI and Tensorflow Lite - Developer Summit · Mobile, AI and Tensorflow Lite Supriya Srivatsa . NEURAL NETWORKS Human anatomy inspired learning network. Neural Networks . Neural

Neural Network – A Peek Inside

Page 9: Mobile, AI and Tensorflow Lite - Developer Summit · Mobile, AI and Tensorflow Lite Supriya Srivatsa . NEURAL NETWORKS Human anatomy inspired learning network. Neural Networks . Neural

Deep Neural Network

Page 10: Mobile, AI and Tensorflow Lite - Developer Summit · Mobile, AI and Tensorflow Lite Supriya Srivatsa . NEURAL NETWORKS Human anatomy inspired learning network. Neural Networks . Neural

PREDICTION AND INFERENCE

How it works today. How it shall work tomorrow.

Page 11: Mobile, AI and Tensorflow Lite - Developer Summit · Mobile, AI and Tensorflow Lite Supriya Srivatsa . NEURAL NETWORKS Human anatomy inspired learning network. Neural Networks . Neural

“Transfer to Infer” Approach

Page 12: Mobile, AI and Tensorflow Lite - Developer Summit · Mobile, AI and Tensorflow Lite Supriya Srivatsa . NEURAL NETWORKS Human anatomy inspired learning network. Neural Networks . Neural

Why On-Device Prediction

• Data Privacy

• Poor internet connections

• Questionable user experience

Page 13: Mobile, AI and Tensorflow Lite - Developer Summit · Mobile, AI and Tensorflow Lite Supriya Srivatsa . NEURAL NETWORKS Human anatomy inspired learning network. Neural Networks . Neural

To The Rescue…

Page 14: Mobile, AI and Tensorflow Lite - Developer Summit · Mobile, AI and Tensorflow Lite Supriya Srivatsa . NEURAL NETWORKS Human anatomy inspired learning network. Neural Networks . Neural

TensorFlow

• Tensor: N Dimensional Arrays

• Open source software library for numerical computation using data flow graphs.

Page 15: Mobile, AI and Tensorflow Lite - Developer Summit · Mobile, AI and Tensorflow Lite Supriya Srivatsa . NEURAL NETWORKS Human anatomy inspired learning network. Neural Networks . Neural

TensorFlow – Data Flow Graphs

• Nodes represent mathematical functions

• Edges represent tensors.

Page 16: Mobile, AI and Tensorflow Lite - Developer Summit · Mobile, AI and Tensorflow Lite Supriya Srivatsa . NEURAL NETWORKS Human anatomy inspired learning network. Neural Networks . Neural

Tensorflow – “Deferred Execution” Model

• Graph first. Computation Afterward.

import tensorflow as tf

x = tf.constant(10)

y = tf.Variable(x + 5)

print(y)

Page 17: Mobile, AI and Tensorflow Lite - Developer Summit · Mobile, AI and Tensorflow Lite Supriya Srivatsa . NEURAL NETWORKS Human anatomy inspired learning network. Neural Networks . Neural

Tensorflow – “Deferred Execution” Model

• Graph first. Computation Afterward.

import tensorflow as tf

x = tf.constant(10)

y = tf.Variable(x + 5)

model = tf.global_variables_initializer()

with tf.Session() as session:

session.run(model)

print(session.run(y))

Page 18: Mobile, AI and Tensorflow Lite - Developer Summit · Mobile, AI and Tensorflow Lite Supriya Srivatsa . NEURAL NETWORKS Human anatomy inspired learning network. Neural Networks . Neural
Page 19: Mobile, AI and Tensorflow Lite - Developer Summit · Mobile, AI and Tensorflow Lite Supriya Srivatsa . NEURAL NETWORKS Human anatomy inspired learning network. Neural Networks . Neural
Page 20: Mobile, AI and Tensorflow Lite - Developer Summit · Mobile, AI and Tensorflow Lite Supriya Srivatsa . NEURAL NETWORKS Human anatomy inspired learning network. Neural Networks . Neural

Packaging the App and the Model

Page 21: Mobile, AI and Tensorflow Lite - Developer Summit · Mobile, AI and Tensorflow Lite Supriya Srivatsa . NEURAL NETWORKS Human anatomy inspired learning network. Neural Networks . Neural

QUANTIZATION

Compress. And Compress More.

Page 22: Mobile, AI and Tensorflow Lite - Developer Summit · Mobile, AI and Tensorflow Lite Supriya Srivatsa . NEURAL NETWORKS Human anatomy inspired learning network. Neural Networks . Neural

Quantization

• Round it up

• Transform: round_weights

• Compression rates: ~8% => ~70%

• Shrink down node names

• Transform: obfuscate_names

• Eight bit calculations

Page 23: Mobile, AI and Tensorflow Lite - Developer Summit · Mobile, AI and Tensorflow Lite Supriya Srivatsa . NEURAL NETWORKS Human anatomy inspired learning network. Neural Networks . Neural

Quantization - Eight Bit Calculations

Page 24: Mobile, AI and Tensorflow Lite - Developer Summit · Mobile, AI and Tensorflow Lite Supriya Srivatsa . NEURAL NETWORKS Human anatomy inspired learning network. Neural Networks . Neural

Quantization - Eight Bit Calculations

Page 25: Mobile, AI and Tensorflow Lite - Developer Summit · Mobile, AI and Tensorflow Lite Supriya Srivatsa . NEURAL NETWORKS Human anatomy inspired learning network. Neural Networks . Neural
Page 26: Mobile, AI and Tensorflow Lite - Developer Summit · Mobile, AI and Tensorflow Lite Supriya Srivatsa . NEURAL NETWORKS Human anatomy inspired learning network. Neural Networks . Neural

IMPLEMENTATION

Code Away!

Page 27: Mobile, AI and Tensorflow Lite - Developer Summit · Mobile, AI and Tensorflow Lite Supriya Srivatsa . NEURAL NETWORKS Human anatomy inspired learning network. Neural Networks . Neural

Implementation

build.gradle

buildscript {

repositories {

jcenter()

}

dependencies {

classpath 'com.android.tools.build:gradle:2.3.0'

} }

Page 28: Mobile, AI and Tensorflow Lite - Developer Summit · Mobile, AI and Tensorflow Lite Supriya Srivatsa . NEURAL NETWORKS Human anatomy inspired learning network. Neural Networks . Neural

Implementation

1. Load

2. Feed

3. Run

4. Fetch

Page 29: Mobile, AI and Tensorflow Lite - Developer Summit · Mobile, AI and Tensorflow Lite Supriya Srivatsa . NEURAL NETWORKS Human anatomy inspired learning network. Neural Networks . Neural

Implementation

1. Load the model

2. Feed in the input

3. Run the model

4. Fetch the output

TensorFlowInferenceInterface inferenceInterface =

new TensorFlowInferenceInterface(assetManager, modelFile);

Page 30: Mobile, AI and Tensorflow Lite - Developer Summit · Mobile, AI and Tensorflow Lite Supriya Srivatsa . NEURAL NETWORKS Human anatomy inspired learning network. Neural Networks . Neural

Implementation

1. Load the model

2. Feed in the input

3. Run the model

4. Fetch the output

// feed(String s, float[] floats, long… longs)

inferenceInterface.feed(inputName, floatValues, 1, inputSize, inputSize, 3);

Page 31: Mobile, AI and Tensorflow Lite - Developer Summit · Mobile, AI and Tensorflow Lite Supriya Srivatsa . NEURAL NETWORKS Human anatomy inspired learning network. Neural Networks . Neural

Implementation

1. Load the model

2. Feed in the input

3. Run the model

4. Fetch the output

inferenceInterface.run(outputNames);

Page 32: Mobile, AI and Tensorflow Lite - Developer Summit · Mobile, AI and Tensorflow Lite Supriya Srivatsa . NEURAL NETWORKS Human anatomy inspired learning network. Neural Networks . Neural

Implementation

1. Load the model

2. Feed in the input

3. Run the model

4. Fetch the output

// fetch(String s, float[] floats)

inferenceInterface.fetch(outputName, outputs);

Page 33: Mobile, AI and Tensorflow Lite - Developer Summit · Mobile, AI and Tensorflow Lite Supriya Srivatsa . NEURAL NETWORKS Human anatomy inspired learning network. Neural Networks . Neural

APPLICATIONS

Awesomeness.

Page 34: Mobile, AI and Tensorflow Lite - Developer Summit · Mobile, AI and Tensorflow Lite Supriya Srivatsa . NEURAL NETWORKS Human anatomy inspired learning network. Neural Networks . Neural

Google Translate

Page 35: Mobile, AI and Tensorflow Lite - Developer Summit · Mobile, AI and Tensorflow Lite Supriya Srivatsa . NEURAL NETWORKS Human anatomy inspired learning network. Neural Networks . Neural
Page 36: Mobile, AI and Tensorflow Lite - Developer Summit · Mobile, AI and Tensorflow Lite Supriya Srivatsa . NEURAL NETWORKS Human anatomy inspired learning network. Neural Networks . Neural
Page 37: Mobile, AI and Tensorflow Lite - Developer Summit · Mobile, AI and Tensorflow Lite Supriya Srivatsa . NEURAL NETWORKS Human anatomy inspired learning network. Neural Networks . Neural

@greatindiandev bit.ly/gidslinkedin www.developersummit.com

Conference and Deep Dive Sessions

April 24-28, IISc Bangalore

TM

2018

Register early and get the best discounts!