1

Requirement

I am developing a photo management Android app that has a labelling feature, it must recognize everyday objects/buildings/animals/plants. When I take a picture that shows a bicycle, a house and a mountain, my app will add the picture to each of these categories.

Tensorflow + pre-trained MobileNet v2 fits the requirement perfectly, with this dependency in my build.gradle:

implementation 'org.tensorflow:tensorflow-android:1.2.0'

Problem

Problem: It makes the APK grow tenfolds to 32 MB, which is unacceptable for my target audience (people with slow/expensive mobile data plans and no WiFi/LAN/broadband).

Question: What tricks can I use to make Tensorflow + pre-trained MobileNet v2 much much smaller?

In particular, how to remove from Tensorflow the classes that are not used when labelling? No training will be done on Android, so I don't need all of the training classes, for instance. I can recompile if needed, but any other method is also welcome.

Nicolas Raoul
  • 58,567
  • 58
  • 222
  • 373
  • Probably you have read this:https://developer.android.com/topic/performance/reduce-apk-size – shizhen Apr 09 '19 at 02:11
  • And [how-to-decrease-the-size-of-android-native-shared-libaries-so-files](https://stackoverflow.com/questions/51784882/how-to-decrease-the-size-of-android-native-shared-libaries-so-files/51814290#51814290) – shizhen Apr 09 '19 at 02:22
  • @shizhen About the first link: I am aware of this page, yes, and I am further looking for something specific to Tensorflow+MobileNet, which makes 90% of the size of the app. About the second link: I did not add any `.so` or `.a` file to my project, but indeed Gradle might be pulling some... if you have significantly reduced the size of a Tensorflow APK using these techniques feel free to post an answer based on these links, thanks! – Nicolas Raoul Apr 09 '19 at 03:11

1 Answers1

0

There is some options you can do to reduce your mode size,

  1. use Mobilenet with alpha 0.25 will reduce model size about 4x smaller
  2. try to convert to .tflite
  3. quantized your .tflite model also will reduce 4x smaller

you can read a lot here, I assume that your model will be 4MB after conversion.