Firebase ML Kit 101 : Image Labeling

Hitanshu Dhawan
Oct 29, 2018 · 5 min read

Firebase ML Kit Series

ML Kit’s Image Labeling

ML Kit’s Image Labeling API available both on device and in cloud
image courtesy: Google I/O ’18

Let’s Code!

Step 1 : Add Firebase to your app

Step 2 : Include the dependencies

dependencies {
// ...

implementation 'com.google.firebase:firebase-ml-vision:18.0.1'
implementation 'com.google.firebase:firebase-ml-vision-image-label-model:17.0.2'
}

Step 2.5 : Specify the ML models (optional)

<application ...>
...
<meta-data
android:name="com.google.firebase.ml.vision.DEPENDENCIES"
android:value="label" />
<!-- To use multiple models: android:value="label,model2" -->
</application>

Step 3 : Get! — the Image

creating FirebaseVisionImage object from different image types
val image = FirebaseVisionImage.fromBitmap(bitmap)

Step 4 : Set! — the Model

val detector = FirebaseVision.getInstance().visionLabelDetector
val options = FirebaseVisionLabelDetectorOptions.Builder()
.setConfidenceThreshold(0.8F)
.build()
val detector = FirebaseVision.getInstance().getVisionLabelDetector(options)
val detector = FirebaseVision.getInstance().visionCloudLabelDetector
val options = FirebaseVisionCloudDetectorOptions.Builder()
.setModelType(FirebaseVisionCloudDetectorOptions.LATEST_MODEL)
.setMaxResults(15)
.build()

val detector = FirebaseVision.getInstance().getVisionCloudLabelDetector(options)

Step 5 : Gooo!

detector.detectInImage(image)
.addOnSuccessListener {
//
Task completed successfully
}
.addOnFailureListener {
//
Task failed with an exception
}

Step 6 : Extract the information

Have a Look!



AndroIDIOTS

An android developer publication to stay updated with whats new in android, best practices and how to become a better android developer

Hitanshu Dhawan

Written by

Software Engineer @UrbanClap | Google Certified Android Developer

AndroIDIOTS

An android developer publication to stay updated with whats new in android, best practices and how to become a better android developer