Make Tensorflow library + pretrained MobileNet as small as possible, to make APK smaller

202 Views Asked by At

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.

1

There are 1 best solutions below

0
Shayan Tabatabaee On

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.