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

时间:2019-04-08 13:00:47

标签: android tensorflow apk size-reduction

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 个答案:

答案 0 :(得分:0)

您可以执行一些选择来减小模式大小,

  1. 将Mobilenet与alpha 0.25一起使用将使模型尺寸减小约4倍 较小
  2. 尝试转换为.tflite
  3. 量化您的.tflite模型还将缩小4倍

您可以阅读很多here,我假设您的模型在转换后将为4MB。