This is a camera app that continuously detects the objects (bounding boxes and classes) in the frames seen by your device's back camera, using a quantized MobileNet SSD model trained on the COCO dataset. These instructions walk you through building and running the demo on an Android device.
The model files are downloaded via Gradle scripts when you build and run. You don't need to do any steps to download TFLite models into the project explicitly.
Application can run either on device or emulator.
- If you don't have already, install Android Studio, following the instructions on the website.
- You need an Android device and Android development environment with minimum API 21.
- Android Studio 3.2 or later.
- Open Android Studio, and from the Welcome screen, select
Open an existing Android Studio project
. - From the
Open File
orProject window
that appears, navigate to and select the/object_detection_demo/02_mobile_app/android
directory. Click OK. - If it asks you to do a Gradle Sync, click OK.
- You may also need to install various platforms and tools, if you get errors like
Failed to find target with hash string 'android-21'
and similar.
Click the Run button (the green arrow) or select Run > Run 'android'
from the top menu.
You may need to rebuild the project using Build > Rebuild Project
.
- If it asks you to use Instant Run, click Proceed Without Instant Run.
- Also, you need to have an Android device plugged in with developer options enabled at this point. See here for more details on setting up developer devices.
Downloading, extraction and placing it in assets folder has been managed automatically by download.gradle.
If you explicitly want to download the model, you can download it from
here.
Extract the zip to get the .tflite
and label
file.
Please do not delete the assets folder content.
If you explicitly deleted the files, then please choose
Build -> Rebuild
from menu to re-download the deleted model files into assets folder.
To use your own model:
- Take existing pre-trained model from the
model zoo,
test it with
demo_1.ipynb
script or train your own model on a new dataset (demo_2.ipynb
). - Create
*.tar.gz
or*.zip
file fromdetect.tflite
with your model andlabelmap.txt
with your labels. Save*.tar.gz
or*.zip
to the Google Drive. Note:labelmap.txt
file should start with???
string, because zero position is reserved. So your class labels will start from the 1st position after???
string. - Get downloadable direct link using direct link generator for Google Drive, Dropbox or Onedrive.
- Replace link in the mobile app
download_model.gradle
file on your link. UsezipTree
for*.zip
andtarTree
for*.tar.gz
. - Our model is not quantized, so set quantized to
false
inDetectorActivity.java
file - Delete
build
folder and cleanassets
folder. Rebuild the project:Build --> Make Project
thenBuild --> Build Bundles --> Build APK
. - Run mobile app (
Run --> Run 'app'
) in Android Studio and enjoy!