TensorFlow Lite for Android (Coding TensorFlow)

TensorFlow · Intermediate ·📰 AI News & Updates ·8y ago

Key Takeaways

The video demonstrates how to use TensorFlow Lite to deploy a trained model on an Android app, allowing for low-latency inference on mobile devices. It covers the basics of TensorFlow Lite, including its support for Android and iOS, and how to use the Java wrapper for Android devices.

Full Transcript

[Applause] hi and welcome to coding tensorflow where you'll learn all about coding machine learning and AI apps using tensorflow I'm Laurence Moroney a developer advocate for tensorflow and today I'll be looking at tensorflow Lite and getting it to run models on Android tensorflow light is tensor flows lightweight solution for mobile and embedded devices and lets you run machine learn models on mobile devices with low latency quickly so you can take advantage of them to do classification regression or anything else you might want to do without necessarily incurring a round trip to a server it's presently supported on Android and iOS via a C++ API as well as a Java wrapper for Android devices on devices that support it the interpreter can also use the Android neural networks API for hardware acceleration otherwise it will default to using the CPU here you can see me running the app on my Android device and using it to classify a number of objects it's quite fun to play with and note how the interpretation of a mouse changes as I move the camera around or the first mug has a high handle which kind of makes it look like a picture so that shows up as a possibility finally my Google mug is broad and looks a bit like a mixing bowl and the app detects that so how does all of this work well let's first talk about the model the app is built using a mobile net model mobile nets are small low latency low-power models that are designed to meet a number of use cases such as object detection face attributes fine grained classification and landmark recognition what's nice about them is that there are a number of different ones that are pre-trained including the model at this link which works for image classification that is compatible with tensorflow lite download that file and you learn zip it to see two files a dot TF Lite file describing the model and a labels file describing the labels that the model is trained for as you can see because your model is already in the TF Lite format it's ready to be run on tensorflow lite so let's take a look at the api's for that in fact i would recommend that you stick with built models for the time being as tensorflow light is a Developer Preview it doesn't support all the operations of tensorflow yet and you might encounter some issues with unsupported ones when you're converting your model to the TF light format okay let's get down to looking at it on a mobile now first of all to use tensorflow light in your android app you need to include the tensorflow light libraries you do this by editing your build up Gradle file to include them once you've done that in synced you'll be able to import a tensorflow interpreter an interpreter loads a model and allows you to run it by providing it with a set of inputs tensorflow light will then execute the model and write the outputs it's really as simple as that of course you have to load the model and the API makes that very straightforward now a good place to store your model is in your app assets the code will then read the model directly from there it doesn't have to be there of course you can load a model from just about anywhere but make sure you get your powers right once you've done that you can instantiate an interpreter and in this case I called it tensorflow light and loaded the model into it let's look at the app again now what's going on here is that it's reading frames from the camera and turning those into images it then uses those images as an input to the model which in turn outputs values these values are an index to the appropriate label and the value for that label the probability that the image matches that label will pick the top three and will write them to the user interface let's take a look at the code first you can see is the input we're getting the image data which is received from the camera as a bitmap we convert that bitmap into a byte buffer which the model can read this buffer is called IMG data remember that we'll come back to it in a moment when you downloaded the model you also had a TF Lite file and a txt file containing labels these labels are a list of all of the objects that the model can recognize here's the first view so for example labeled zero is background label two is goldfish and so on remember the image data from a moment ago well we'll load into our tensorflow light interpreter and we'll get an output called label proper ray it's probably easiest if we look at that in the debugger so here you can see I had a breakpoint on looking at a picture of my mug as you can see the top elements unless the goldfish etc have very very low probability indeed it's like 1.7 nine times 10 to the minus 5 but when you scroll through the output lists you'll see for example that label 505 has a relatively high priority and number 505 corresponds to coffee cup which as you'll remember from the video that's what I was looking at if you want to try an app for yourself that does all of this you can get it on github at this link and that's a starter intensive flow light for Android this exciting technology will let you load all your models onto an Android device taking advantage of onboard hardware and allow you to execute them I showed an example using image recognition in a video stream but of course you're not limited to that at the moment tensorflow light is in Developer Preview so you may encounter some restrictions in operations that are supported but we're updating it all the time finally if you want to learn more including how to retrain the model I showed in this video to tailor it for specific scenarios check out the tensor flow for poet code labs on the Google developer site I can't wait to see what you build on mobile with tensorflow Lite and don't forget to hit that subscribe button for more great coding with tensorflow videos Cheers don't forget to click the subscribe button for more great videos like these what's

Original Description

In this episode of Coding TensorFlow, Laurence Moroney, Developer Advocate for TensorFlow at Google, talks us through how TensorFlow Lite works on Android. You'll see how to deploy a trained model to an Android App, and how you can run inference with it in Java. “Building TensorFlow on Android” article → https://goo.gl/B8SV2d TensorFlow Lite Demo for Android → https://goo.gl/nWAipo Subscribe to the channel to catch new episodes of Coding TensorFlow → https://goo.gl/ht3WGe Watch more Coding TensorFlow episodes here → https://goo.gl/cezxSW
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from TensorFlow · TensorFlow · 32 of 60

1 The TensorFlow YouTube Channel is Here!
The TensorFlow YouTube Channel is Here!
TensorFlow
2 Answering Your TF Questions #AskTensorFlow
Answering Your TF Questions #AskTensorFlow
TensorFlow
3 Chatting With the TensorFlow Community (TensorFlow Meets)
Chatting With the TensorFlow Community (TensorFlow Meets)
TensorFlow
4 All About TensorFlow Code (Coding TensorFlow)
All About TensorFlow Code (Coding TensorFlow)
TensorFlow
5 TensorFlow: an ML platform for solving impactful and challenging problems
TensorFlow: an ML platform for solving impactful and challenging problems
TensorFlow
6 Keynote (TensorFlow Dev Summit 2018)
Keynote (TensorFlow Dev Summit 2018)
TensorFlow
7 tf.data: Fast, flexible, and easy-to-use input pipelines (TensorFlow Dev Summit 2018)
tf.data: Fast, flexible, and easy-to-use input pipelines (TensorFlow Dev Summit 2018)
TensorFlow
8 Eager Execution (TensorFlow Dev Summit 2018)
Eager Execution (TensorFlow Dev Summit 2018)
TensorFlow
9 Machine Learning in JavaScript (TensorFlow Dev Summit 2018)
Machine Learning in JavaScript (TensorFlow Dev Summit 2018)
TensorFlow
10 Training Performance: A user’s guide to converge faster (TensorFlow Dev Summit 2018)
Training Performance: A user’s guide to converge faster (TensorFlow Dev Summit 2018)
TensorFlow
11 The Practitioner's Guide with TF High Level APIs (TensorFlow Dev Summit 2018)
The Practitioner's Guide with TF High Level APIs (TensorFlow Dev Summit 2018)
TensorFlow
12 Distributed TensorFlow (TensorFlow Dev Summit 2018)
Distributed TensorFlow (TensorFlow Dev Summit 2018)
TensorFlow
13 Debugging TensorFlow with TensorBoard plugins (TensorFlow Dev Summit 2018)
Debugging TensorFlow with TensorBoard plugins (TensorFlow Dev Summit 2018)
TensorFlow
14 TensorFlow Lite (TensorFlow Dev Summit 2018)
TensorFlow Lite (TensorFlow Dev Summit 2018)
TensorFlow
15 Searching Over Ideas (TensorFlow Dev Summit 2018)
Searching Over Ideas (TensorFlow Dev Summit 2018)
TensorFlow
16 Reconstructing Fusion Plasmas (TensorFlow Dev Summit 2018)
Reconstructing Fusion Plasmas (TensorFlow Dev Summit 2018)
TensorFlow
17 Nucleus: TensorFlow toolkit for Genomics (TensorFlow Dev Summit 2018)
Nucleus: TensorFlow toolkit for Genomics (TensorFlow Dev Summit 2018)
TensorFlow
18 Open Source Collaboration (TensorFlow Dev Summit 2018)
Open Source Collaboration (TensorFlow Dev Summit 2018)
TensorFlow
19 Swift for TensorFlow - TFiwS (TensorFlow Dev Summit 2018)
Swift for TensorFlow - TFiwS (TensorFlow Dev Summit 2018)
TensorFlow
20 TensorFlow Hub (TensorFlow Dev Summit 2018)
TensorFlow Hub (TensorFlow Dev Summit 2018)
TensorFlow
21 Applied AI at The Coca-Cola Company (TensorFlow Dev Summit 2018)
Applied AI at The Coca-Cola Company (TensorFlow Dev Summit 2018)
TensorFlow
22 Real-World Robot Learning (TensorFlow Dev Summit 2018)
Real-World Robot Learning (TensorFlow Dev Summit 2018)
TensorFlow
23 TensorFlow Extended (TFX) (TensorFlow Dev Summit 2018)
TensorFlow Extended (TFX) (TensorFlow Dev Summit 2018)
TensorFlow
24 Project Magenta (TensorFlow Dev Summit 2018)
Project Magenta (TensorFlow Dev Summit 2018)
TensorFlow
25 TensorFlow Dev Summit 2018 - Livestream
TensorFlow Dev Summit 2018 - Livestream
TensorFlow
26 Introducing TensorFlow Lite (Coding TensorFlow)
Introducing TensorFlow Lite (Coding TensorFlow)
TensorFlow
27 TensorFlow Dev Summit 2018 Highlights
TensorFlow Dev Summit 2018 Highlights
TensorFlow
28 Jeff Dean, Head of AI at Google discusses the impact of ML (TensorFlow Meets)
Jeff Dean, Head of AI at Google discusses the impact of ML (TensorFlow Meets)
TensorFlow
29 TensorFlow Mobile vs. TF Lite and More! #AskTensorFlow
TensorFlow Mobile vs. TF Lite and More! #AskTensorFlow
TensorFlow
30 Using TensorFlow to enable research & production across many fields (TensorFlow Meets)
Using TensorFlow to enable research & production across many fields (TensorFlow Meets)
TensorFlow
31 Teaching TensorFlow for Deep Learning at Stanford University (TensorFlow Meets)
Teaching TensorFlow for Deep Learning at Stanford University (TensorFlow Meets)
TensorFlow
TensorFlow Lite for Android (Coding TensorFlow)
TensorFlow Lite for Android (Coding TensorFlow)
TensorFlow
33 Using the tf.data API to build input pipelines (TensorFlow Meets)
Using the tf.data API to build input pipelines (TensorFlow Meets)
TensorFlow
34 Training Models in the Cloud & the Benefits of AI Toolkits #AskTensorFlow
Training Models in the Cloud & the Benefits of AI Toolkits #AskTensorFlow
TensorFlow
35 Execute operations immediately with TensorFlow's Eager Execution (TensorFlow Meets)
Execute operations immediately with TensorFlow's Eager Execution (TensorFlow Meets)
TensorFlow
36 TensorFlow Lite for iOS (Coding TensorFlow)
TensorFlow Lite for iOS (Coding TensorFlow)
TensorFlow
37 Get started with TensorFlow's High-Level APIs (Google I/O '18)
Get started with TensorFlow's High-Level APIs (Google I/O '18)
TensorFlow
38 TensorFlow for JavaScript (Google I/O '18)
TensorFlow for JavaScript (Google I/O '18)
TensorFlow
39 TensorFlow in production: TF Extended, TF Hub, and TF Serving (Google I/O '18)
TensorFlow in production: TF Extended, TF Hub, and TF Serving (Google I/O '18)
TensorFlow
40 Get started with TensorFlow's High-Level APIs in 5 mins |  Google I/O 2018
Get started with TensorFlow's High-Level APIs in 5 mins | Google I/O 2018
TensorFlow
41 TensorFlow and deep reinforcement learning, without a PhD (Google I/O '18)
TensorFlow and deep reinforcement learning, without a PhD (Google I/O '18)
TensorFlow
42 TensorFlow Lite for mobile developers (Google I/O '18)
TensorFlow Lite for mobile developers (Google I/O '18)
TensorFlow
43 Advances in machine learning and TensorFlow (Google I/O '18)
Advances in machine learning and TensorFlow (Google I/O '18)
TensorFlow
44 Distributed TensorFlow training (Google I/O '18)
Distributed TensorFlow training (Google I/O '18)
TensorFlow
45 Classification using neural networks & ML regression models #AskTensorFlow
Classification using neural networks & ML regression models #AskTensorFlow
TensorFlow
46 TensorFlow and Keras in R - Josh Gordon meets with J.J. Allaire (TensorFlow Meets)
TensorFlow and Keras in R - Josh Gordon meets with J.J. Allaire (TensorFlow Meets)
TensorFlow
47 Focus on your experiment with TensorFlow Estimators (TensorFlow Meets)
Focus on your experiment with TensorFlow Estimators (TensorFlow Meets)
TensorFlow
48 How to get started with AI/ML, retraining models, & more! #AskTensorFlow
How to get started with AI/ML, retraining models, & more! #AskTensorFlow
TensorFlow
49 TensorFlow - the deep learning solution for mobile platforms (TensorFlow Meets)
TensorFlow - the deep learning solution for mobile platforms (TensorFlow Meets)
TensorFlow
50 MiniGo: TensorFlow Meets Andrew Jackson (TensorFlow Meets)
MiniGo: TensorFlow Meets Andrew Jackson (TensorFlow Meets)
TensorFlow
51 The growth of TensorFlow with added support for JS & Swift (TensorFlow Meets)
The growth of TensorFlow with added support for JS & Swift (TensorFlow Meets)
TensorFlow
52 At the intersection of TensorFlow & nuclear physics (TensorFlow Meets)
At the intersection of TensorFlow & nuclear physics (TensorFlow Meets)
TensorFlow
53 NVidia TensorRT: high-performance deep learning inference accelerator (TensorFlow Meets)
NVidia TensorRT: high-performance deep learning inference accelerator (TensorFlow Meets)
TensorFlow
54 Try TensorFlow.js in your browser (Coding TensorFlow)
Try TensorFlow.js in your browser (Coding TensorFlow)
TensorFlow
55 TensorFlow Hub: reusing machine learning modules (TensorFlow Meets)
TensorFlow Hub: reusing machine learning modules (TensorFlow Meets)
TensorFlow
56 How to use TensorFlow in PyCharm (TensorFlow Tip of the Week)
How to use TensorFlow in PyCharm (TensorFlow Tip of the Week)
TensorFlow
57 Training models faster with TensorFlow Hub (TensorFlow Meets)
Training models faster with TensorFlow Hub (TensorFlow Meets)
TensorFlow
58 Prepare your dataset for machine learning (Coding TensorFlow)
Prepare your dataset for machine learning (Coding TensorFlow)
TensorFlow
59 Using ML to predict insulin use for Type 1 Diabetes (TensorFlow Meets)
Using ML to predict insulin use for Type 1 Diabetes (TensorFlow Meets)
TensorFlow
60 TFX: an end-to-end machine learning platform for TensorFlow (TensorFlow Meets)
TFX: an end-to-end machine learning platform for TensorFlow (TensorFlow Meets)
TensorFlow

This video teaches how to use TensorFlow Lite to deploy machine learning models on Android devices, allowing for low-latency inference. It covers the basics of TensorFlow Lite and how to use it in Android app development.

Key Takeaways
  1. Download a pre-trained MobileNet model
  2. Convert the model to TensorFlow Lite format
  3. Include the TensorFlow Lite libraries in your Android app
  4. Load the model into the TensorFlow Lite interpreter
  5. Run inference on the model using the interpreter
💡 TensorFlow Lite allows for low-latency inference on mobile devices, making it possible to deploy machine learning models on Android apps.

Related Reads

📰
Hyundai and Kia built a UV system that kills bacteria inside a car while you are sitting in it
Hyundai and Kia develop an in-vehicle UV system to kill bacteria and viruses while passengers are present, using far-ultraviolet light technology
The Next Web AI
📰
The latest AI news we announced in June 2026
Get the latest AI news from Google's June 2026 updates and stay current with industry developments
Google AI Blog
📰
AI-Powered Theodore Roosevelt Is Ready To Answer Your Questions
Learn about the AI-powered Theodore Roosevelt avatar at the presidential library, which showcases innovative applications of AI in education and history
Forbes Innovation
📰
Krafton agrees to pay Subnautica 2 bonuses after CEO who used ChatGPT to dodge them steps down
Krafton agrees to pay bonuses to Subnautica 2 staff after CEO steps down, highlighting the importance of transparency and accountability in leadership
The Next Web AI
Up next
FABLE 5 IS BACK
Wes Roth
Watch →