A Guide to Running Tensorflow Models on Android

Let’s create an Android app that uses a pre-trained Tensorflow image classifier for MNIST digits to recognize what the user draws on the screen. We’ll use Android Studio and the gradle build system to make it happen.

Code for this video:
https://github.com/llSourcell/A_Guide_to_Running_Tensorflow_Models_on_Android

Please subscribe! And like. And comment. That’s what keeps me going.

More learning resources:
https://github.com/tensorflow/tensorflow/tree/master/tensorflow/examples/android
https://www.tensorflow.org/mobile/
https://www.oreilly.com/learning/tensorflow-on-android
https://blog.mindorks.com/android-tensorflow-machine-learning-example-ff0e9b2654cc
https://venturebeat.com/2017/05/17/android-launches-tensorflow-lite-for-mobile-machine-learning/
http://nilhcem.com/android/custom-tensorflow-classifier
https://medium.com/@daj/creating-an-image-classifier-on-android-using-tensorflow-part-1-513d9c10fa6a
https://omid.al/posts/2017-02-20-Tutorial-Build-Your-First-Tensorflow-Android-App.html

Join us in the Wizards Slack Channel:
http://wizards.herokuapp.com/

And please support me on Patreon:
https://www.patreon.com/user?u=3191693
Follow me:
Twitter: https://twitter.com/sirajraval
Facebook: https://www.facebook.com/sirajology Instagram: https://www.instagram.com/sirajraval/

Comments

Andreas V says:

Damn, you’re funny! And informative. And you got yourself a new subscriber! Good vid bro, I was looking around about how to deploy tf models to my phone, I only found videos about deploying it to servers. This vid was nice!

How about to normal computers? I’ve only seen people recommending Kubernetes or Docker, but it seems overkill.

Ivorian Koua says:

Sir thanks alot for this even in I haven’t right learn Android Developpment or write on code of TenserFlow project but it’s really exciting to see you do it and also motivating so THANKS SIR

Sulaiman Ayaz says:

Dude, great job, seriously man keep up the good work.

firefreak says:

I am getting this error when i try to deploy my own keras pb file.

No OpKernel was registered to support Op ‘DecodeJpeg’ with these attrs

any ideas?

Petrus Hishekwa says:

Siraj this is a very nice video. Can you please refer me to a video that can help me identify student number from a student card image using tensorflow that can run on an android device.

Ramanujam M says:

congrats and thank u your video is super…

Anil Vootukuru says:

Thanks for video Siraj, very informative. Do you have a similar video on how to use a .h5 Keras model in an android app

Samuel Böhme says:

Thanks for the awesome tutorial. I’m really looking forward for a android tutorial “how to use tensorflow image recognition with pictures from your gallery” Would be awesome if you could do one

ian schoenrock says:

DOPE.

venkat mamindla says:

Hi Siraj, I love this video … I was build a android app successfully … Similar way i am trying to build a app for sentiment analysis … I am trying to generate .pb file but i have a doubt .. what is the significant of input_node_name and output_node_name in Export model method ….
In my model i have embedded layer + LSTM + DNN … so what should i give input_node_name and output_node_name.

coooltroll Nub says:

U were the one who introduced me into this wonderful world of machine learning. I’m seriously inspired and have found something part of my life’s purpose. I now extremely happy to finally find a detailed video on implementing tensorflow into android

Ankush Naik says:

can we develop a traffic sign recognition app using cnn using similar approach??

Robert Lam says:

Great effort. Learned so much……. thanks

Kyzuuh says:

Hey Siraj really great video. I think these are my favorite video style, the 5 minute videos are interesting, but this is the type of video I can actually learn to do something from.

Diaz Agasatya says:

amazing.. tho my brain is hurting right now lol

Abdul Wahid says:

Is the process similar in a Linux platform like ubuntu?

ZupArt says:

Awesome video! This was the first video that had a better paste for me. I’ve watched several videos that has been uploaded from you, but as a new programmer in this field I felt lost after 15 sec. But instead of getting lost this time, I got excited to start working with ML. Keep it up!

Ruoyu Qian says:

is it possible to load models that trained by weka and import it onto android apps?

onkar gupta says:

Can we implement unsupervised learning model ?

Tiarnan Swayne says:

Really liked this video, just seeing some errors you ddin’t adress. Is there a way to contact you?

Jian James Astrero says:

Not sure if you cant explain android, or its your first time using android.

Hash Root says:

Adding ” compile ‘org.tensorflow:tensorflow-android:+’ ” to the dependencies section of the gradle file automatically downloaded the AAR file. Thanks Siraj for this awesome tutorial!!

Anik kumar Bhushan says:

your education channel ROCKS!

Vedant Mhatre says:

Do you have job

Tran Hai says:

Please help me answer this question, this is my model in Keras:

model = Sequential()
model.add(Dense(784, input_dim=784, kernel_initializer=’normal’, activation=’relu’))
model.add(Dense(10, kernel_initializer=’normal’, activation=’softmax’))
model.compile(loss=’categorical_crossentropy’, optimizer=’adam’, metrics=[‘accuracy’])

So what value should I put in the “input_node_names” and “output_node_name” variables in the “export_model” function? (file mnist_convnet_keras.py)

Isaac Kargar says:

Thank you for your great tutorial. Where can I download tensorflow android release package (AAR)?

Naveen Cooray says:

hi siraj! thanks alot for the much needed video. btw, i would like to know few things as im pretty much a noob at ML.
1. can we use this model to build a speech recognition algorithm?
2. how to upload this into a server ?
3. what is the best ANN type to process natural language (what a user speaks) and response accordingly? CNN or RNN
4. can you clarify how to build the connection between the android app and the tensorflow (which is deployed in a server)

I would be extremely grateful if you could reply. Thanks for all the videos you have done. and please do more. specially android based ML & NLP. cheers!

Shubham Srivastava says:

Sr I want to load models from byte data rather than loading model from filepath in tensorflow(means i want to store containt of model file in byte array and initialise Inference by passing this byte array) in android studio.Please explain how we can customize tensorflow library to do this

Abhishek shukla says:

Can someone explain me what does x_train , y_train, x_test and y_test stand for? Like why are we using two variables x and y? Please help

Tech Weby says:

help me with this plzz https://github.com/tensorflow/tensorflow/tree/master/tensorflow/contrib/android   I want to run it and I m not getting it’s documentation tell me in steps

Hitesh Vaidya says:

bhai tum tshirt khadi gramodyog se lete ho kya? kafi ache dikhte hai.

Mohamad Audhil says:

Hi Siraj, I love your videos, I’m an Android developer, You are rock star, you took so much pain to write comments for the project imports too. Wow! Hats off to you!

Christos F says:

I am using windows OS and I have a couple of problems with the commands. Is it better to have linux for easier handling of opensource projects?

Jiko Jj says:

U cannot really use eclipse anymore with the newest apis

Prince Johar says:

how can i change that image detector to a image capture and predicting the image ?

Aditya Raj Tiwari says:

YOu are good brah very good indeed

Trí Đông A says:

so crazy but awesome :)))

Tony770jr says:

I appreciate that you are trying to help with TensorFlow, but your body movements in the video detract from it. Better to narrate only…

Filoktimon Repoulias says:

Congratulations for your work Siraj!

sibo teng says:

you scared me with your eyeballs

eng mohamed says:

i must first setup tensorflow or i can use model directly on android without needing tensorflow on windows

Martin Peniak says:

SDK stands for software development kit not standard development kit 😀

ryan bennett says:

You explain things SO well. I’m about a month into Android development and the commenting on your code has really helped me grasp the concepts I’ve been coding. Thanks

Ephrem Tadesse says:

lovely

Cindy Chen says:

can you make a introduction or a guide for the tensorflow lite ?

Jorge Luis Rangel García says:

I just love your channel. Every time I find something new on about ML and want to see a video about it, you have it. Thanks a lot!!!!

Was geht says:

First of all it is amazing, thank u 😀 Second , i copy the code from GitHub and test it on my smartphone but the results are very bad , i don’t know why

Yasir Raza says:

Great tutorial… Can you please tell me how to recognize sign languages in android?

Sabir Ullah says:

Siraj Raval can you give me a small demo on skyp i will pay it for you

 Write a comment

*

Do you like our videos?
Do you want to see more like that?

Please click below to support us on Facebook!