Build Android App with TensorFlow Lite Machine Learning Model

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this lecture we are going to learn how to take a tensorflow lite model and how to use it in an android studio app so our first step is going to be to build an android studio app from scratch so open up android studio and select new project here make sure you select the template of empty activity there's lots of different templates that you can use we just need an empty activity and make sure you select that one instead of any of the others not no activity but empty activity then hit next and give your application a name such as the linear regression app right so whatever you'd like you can call it linear regression choose a package name and a save location this is where the project folder will be created the language that we're going to use is kotlin this is the next advancement after java kotlin is going to overtake java eventually as the primary android app development language there's also java but we're going to use kotlin in this course you could use java if you'd like but kotlin is recommended next choose a minimum sdk you want to choose an sdk that can run on a lot of devices we don't need any legacy android support libraries once you are done with putting in the data for the project hit finish and that is going to launch for you android studio so here we are in android studio and we have our first file here a class main activity currently our project files are loading so let's just wait for them to load okay here we go we have them loaded now we have a manifests file containing androidmanifest.xml double click on that to open it this contains the basic launching schema for the app we also have a java folder which might be confusing since we did select kotlin but that just stores the kotlin or java files for the project because we selected an empty activity we actually do get a main activity here you want to make sure you have main activity if you don't have it you can create it yourself it's a kotlin file and it's created whenever you select an empty activity if you selected no activity then you won't actually have this we also have some test files for testing the app then we have resources this res folder which has images as well as layout files like the activity main xml file you can see it actually contains the layout of the app which you can view in code in split or in design mode all right so here is what the app looks like currently just says hello world we also have some launcher images and values inside of the resources folder there's also a gradle scripts which contains build information all right now the first thing we need to do is to add our tensorflow lite model to our project so we are going to create a new folder inside of the app folder and that will be a folder to contain our resources so inside of app let's build another folder instead of this res let's build one specifically for model resources so i'm going to right click and create a new directory which is a folder okay then you can select the name for your directory let's do source and then we can do slash followed by main okay so i'm just going to create that and if you're using a new directory it also option wants you to use a prompt so if you don't want to build a directory via kotlin you can also just do it via your finder so you can just right click on the file and then you can just open it inside of your file explorer and just build the files that way so here inside of your file explorer you have your project with your app so here i have linear regression i have the app then if you go into source and main you'll see here you have java and resources so the resources contains the images the layouts the values and then the java actually contains your whole app activities which currently we just have one so we want to go into one of these let's just go back we want to go into the main project container so we have here main and inside of main next to java and resources we want to right click create a new folder we are going to call this one assets and then you want to just copy your tensorflow lite model into this assets folder here i have copied my linear regression file the linear regression model.tflight into that assets folder okay so now we are ready to start using the model inside of the project so here inside of android studio we want to open the build.gradle at the module level because you have two gradle scripts you want to open build.gradle at the module app level then in here we want to add some code below the build types so here we have build types this year we have which sdk we're compiling for our default configuration our build types kotlin options and dependencies okay we want to add underneath build types a new option here called aapt options and we want to say no compress tf light so this will make sure that our tensorflow lite file will not be compressed when the app apk is built so this refers to the application programming kit so when the app apk is created we will not compress the tensorflow lite file otherwise by default it would be compressed we also want to add a dependency to our list of dependencies and that dependency is going to be tensorflow lite itself so here i'm going to add implementation org.tensorflow tensorflow dash light plus this will grab for us the latest version of tensorflow lite and you want to make sure that you include this otherwise you cannot implement tensorflow lite into the project now at the top of your file you now have to sync your changes because whenever you make a change to a gradle file your project has to sync so hit sync now okay and that is all you need to do to sync the project pledge to our kickstarter the complete 22 web development and machine learning bundle which also has a lot of app development content and it is live now link in description
Info
Channel: MammothInteractive
Views: 12,382
Rating: undefined out of 5
Keywords: android tensorflow lite, beginners android tf lite tutorial, android tensorflow tutorial, beginners android tensorflow, android machine learning tutorial, beginners android machine learning, android ml tutorial, beginners android ai tutorial
Id: o5c2BLrxNyA
Channel Id: undefined
Length: 7min 58sec (478 seconds)
Published: Wed Dec 01 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.