Welcome back.
We finished the object detector class.
Now let's create the view model.
Inside this package, create a new package called View Model and inside it create a new Kotlin class.
Name it as Detection View model.
If you remember, we added Hilt Dependency Injection library to our Gradle file.
So we're going to use here to do the dependency injection.
And as we learned before the view model will be marked as hilt view model.
Please go back to the dependency injection section in order to learn more about the hilt view model.
Also we need to inject the constructor with inject annotation and here we need the private val context
context and this dependency can be provided by hilt by using another annotation called Application Context,
and to tell Android Studio that this class will act as a ViewModel, we need to extend from ViewModel.
Now let's create a companion object, which is which is containing the constants that we need to use
companion object.
And here let me start with the constant val tag equals to tag.
This is for luck.
Also we need to add the model file name and label file name.
Let's start with constant val model file name and the constant val label file name.
Let's add the model that we, uh, we downloaded from SSD MobileNet and from Kaggle website.
To add it, it's very simple.
Inside this app, create a new other TensorFlow Lite model.
Click on it, Locate your model.
Select the flight automatically.
Add build feature and dependencies to build your Gradle.
Keep it like this and click finish.
Wait for Android Studio to add the model to the ML file and folder.
And this is our model.
If you notice that we have an int array of one 300 303, data type is unsigned integer eight.
Okay.
We talked about the shape of our model.
And this is just a confirmation of the inputs shapes.
Okay.
So this is our model.
Add it inside the ML package that is created by Android Studio.
The second step is the label file.
Go to Google search for download Coco dataset labels version one dot txt.
Here we have the annotations.
The train 2017.
It's similar.
You can go to Coco dataset to download the whole data sets, but there are a lot of libraries that provide
you with the labels.
You can go to GitHub.
Me leave labels.
I clicked on this repository and you can download the Coco labels 2014 2017.
Those are the labels.
Copy them or you can download them as a row like this copy.
And here we need to create the text file.
Create a new text document.
Name it as Coco data, set labels, open it and paste those labels.
Click save.
And here we go.
This is the Coco data set labels.
Let's go to Android Studio and copy this file into the folder.
Paste and click okay.
Those are the labels starting from person and ending with tooth brush.
Okay, now let's add the model file name.
Here we have, uh, the Coco data set labels and mobile as the SSD MobileNet version one Tflite.
Please pay attention for the name so it's case sensitive.
It's called SSD underscore MobileNet underscore version one TF Lite.
Make sure that it is um highlighted by green.
So you hit the correct file.
Then use the label file name.
The label file name is Coco.
This is the name Coco.
Underscore data set underscore labels dot txt okay.
It's highlighted by green and it's hitting the correct file okay.
In this way we added the SSD mobile version one tflite file and the Coco dataset labels.