bazel0.18.1 编译 tensorflow1.12,使用TFLite将ssdmobilenet移植至安卓客户端,实打实能装
1 安装基础依赖
sudo apt install python-pip
sudo apt-get install pkg-config zip g++ zlib1g-dev unzip python
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple mock six numpy wheel enum
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple keras_applications==1.0.5 --no-deps
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple keras_preprocessing==1.0.3 --no-deps
2 安装 bazel(https://docs.bazel.build/versions/master/install-ubuntu.html#install-with-installer-ubuntu)
https://github.com/bazelbuild/bazel/releases/download/0.24.1/bazel-0.24.1-installer-linux-x86_64.sh
chmod +x bazel-0.18.1-installer-linux-x86_64.sh
./bazel-0.18.1-installer-linux-x86_64.sh --user
3 编译
bazel build tensorflow/contrib/lite/toco:toco
4 转tflite模型,以moiblenet ssd为例
4.1 转换checkpoint为tflite_graph.pb
无论ssdlite_mobilenet_v2_coco正常bp模型,还是ssd_mobilenet_v1_quantized_cocotflite模型都要先export_tflite_ssd_graph.py处理ckpt,再toco转tflite
python3 object_detection/export_tflite_ssd_graph.py --pipeline_config_path=models/modelzoo/ssd_mobilenet_v1_coco_2018_01_28/pipeline.config --trained_checkpoint_prefix=models/modelzoo/ssd_mobilenet_v1_coco_2018_01_28/model.ckpt --output_directory=./
4.2 转换tflite_graph.pb为detect.tflite
bazel run tensorflow/contrib/lite/toco:toco -- --input_file=/home/s2/tensorflow-r1.12/tflite_graph.pb --output_file=/home/s2/tensorflow-r1.12/detect.tflite --input_shapes=1,300,300,3 --input_arrays=normalized_input_image_tensor --output_arrays='TFLite_Detection_PostProcess','TFLite_Detection_PostProcess:1','TFLite_Detection_PostProcess:2','TFLite_Detection_PostProcess:3' --inference_type=FLOAT --allow_custom_ops
inference_type可定义是FLOAT 还是 QUANTIZED_UINT8