Skip to main content

How To Implement AutoML Vision Edge Of Firebase ML Kit In Android Studio 2020 | 5 Simple Step | Step By Step Tutorial

Today, In this post we're going to implement the AutoML vision edge of firebase ml kit in a very 5 simple steps in Android Studio.

This is how the app work after doing all the steps:
 
                           


Step 1: Add Firebase to Android Project :

If you have not added firebase to your android project then do it so I recommend you to go through the post how to add firebase within 5 min 2020 to the android project.

Step 2: Download Flower - Image Dataset:

We're using the flower-image dataset from TensorFlow to create the image classification or labeling model and after training this model you can use it for an on-device image labeling in your app.

In our case, we are using the 5 labels or type daisy, dandelion, roses, sunflowers, and tulips of flower and the model identifies one of the labels for an image.

Download the flower-image dataset.

Step 3: Upload and Train Dataset:

Go to  Firebase Console -> ML Kit and click on Get Started.


Then go to AutoML and click on Get Started.


Click on Continue and wait for 5 minutes.


Now Click on Add dataset.


Give a name to the dataset and select the second option, then click on Continue.


Now, Click on browse file and select the flower image dataset a .zip file that you download earlier in Step 2.


Now, wait for some time while all 3 steps get completed.

After that, click on Train model-


Now select the third option (High accuracy) and click on start training.


Now, wait until the training of the model is complete.

Step 4: Use Trained Model :

Click on the first model in models list and keep a note on the model name we need it later-


Now, click on Use Model -


There are 2 ways you can use this model -
(i) Remotely (Publish to firebase and load it remotely from your app at run time)
(ii) Locally (Download and Bundle with your app)

You can see a detailed comparison b/w two on that page.

We're using both ways locally and remotely to use this model.

So first let's publish the model by click on the publish button and then click on download and save the zip file at your desired location.


After that extract the downloaded zip file and then copied all three files.


Now go to Android Studio and then,
Right-click on the app select New->Folder->Asset Folder


Then click on Finish.
Now, make a directory in assets folder by right click on assests->New->Directory


Give a name e.g model and click on enter.
Now, paster all three copied files in this folder-


Step 5: Label image:

Add the following to your app's build.gradle file to ensure Gradle doesn't compress the model file when building the app:
android {
    // ...
    aaptOptions {
        noCompress "tflite"
    }
}

as shown below:


now, add these two dependencies for the ML Kit Android libraries in app-level build.gradle:

 implementation 'com.google.firebase:firebase-ml-vision:24.0.1'
 implementation 'com.google.firebase:firebase-ml-vision-automl:18.0.3'

Now add a Button, ImageView, and TextView to Select the image, display the image and show the labels with predication percentage in the activity layout.


Now, I recommend you to through the post how to select(capture image) android studio 2020 before going further.

This is how we get a label of an input image:
1. Load the model
2. Preparing the input image
3. Run the image labeler

1. For Remote model:-

1. Declare all variable -



2. Load the model -





3. Preparing the input image -





4. Run the image labeler -



2. For Local model:-

1. Declare all variable and select image-





2.  Load the model -



3.  Run the image labeler -



Now you can run the app and after that try with different datasets.

You can see the full source code at GitHub.

If you face any problem or have any suggestion please comment it down we love to answer it.

Comment down what next topic you need a guide on? or Drop a message on our social media handle

 Happy coding and designing : )



Comments

Popular posts from this blog

Select (or Capture) and Crop Image In Android Studio 2020 (Complete Guide) | Step By Step Guide

In, this post we're going to make an app that captures or selects an image and then displays in an image view using a third party library - android image cropper by ArthurHub at Github. Step 1: Add Dependency : Open android studio and paste this dependency in app-level build.gradle file as shown below: implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.+' and then click on Sync Now. Step 2: Design the main activity layout : Add a Button and an ImageView to select and display image respectively as shown below: Step 3: Modify AndroidMainfest.xml by adding the CropImageActivity : <activity android:name="com.theartofdev.edmodo.cropper.CropImageActivity" android:screenOrientation="portrait" android:theme="@style/Base.Theme.AppCompat"/>  as shown below- Step 4: Open CropImageActivity on Click of a button : Step 5: Lastly, override the On Activity Result and update ImageView : ...

Detect and Track Object Using Firebase ML Kit In Android Studio 2020(Complete Guide) With Source Code | Step By Step Tutorial

In this post, we're going to detect and track an object in an image using a firebase ml kit in an android studio. This is the output after doing all the steps: So, now make it happen: Step 1: Add Firebase to your android project: I recommend you to see  how to add firebase to the android project in 5minutes  to know how to add it or if you already add it then you can move on to 2nd Step.  Step 2: Add this dependency for the ml kit android libraries to your app-level build.gradle file: implementation 'com.google.firebase:firebase-ml-vision:24.0.1' implementation 'com.google.firebase:firebase-ml-vision-object-detection-model:19.0.3' as shown below and then click on Sync Now. Step 3: Design the layout of the activity: <? xml version ="1.0" encoding ="utf-8" ?> <RelativeLayout xmlns: android ="http://schemas.android.com/apk/res/android" android :layout_width ="match_parent" android :la...

Make Barcode Scanner App Using Firebase ML Kit In Android Studio 2020(Complete Guide) With Source Code | Step By Step Tutorial

In this post, we're going to develop an android app that scans the barcode from the image and produce the required output. This is the output after doing all the steps: You can create your own QR Code from a  barcode generator  with custom data like putting a URL or a mail message etc. The above one is a simple text QR Code. The highlighted text in the above screenshot is the same output you get if you scan the above QR Code with Google Lens. As I show it below: So, Now let's make it. Step 1: Add Firebase to your android project: I recommend you to see  how to add firebase to the android project in 5minutes  to know how to add it or if you already add it then you can move on to 2nd Step.    Step 2: Add this dependency for the ml kit android libraries to your app-level build.gradle file: implementation 'com.google.firebase:firebase-ml-vision:24.0.1' implementation 'com.google.firebase:firebase-ml-vision-barcode-model:16.0.2' ...



DMCA.com Protection Status

Copywrite © 2021 The MindfulCode