首页 技术 正文
技术 2022年11月11日
0 收藏 796 点赞 2,248 浏览 1421 个字

环境

tensorflow = 1.12.0
bazel = 0.18.1
ubuntu = 16.04
python = 3.6.2

安装 bazel (0.18.1)

如果tensorflow是1.12.0,那么必须安装指定版本0.18.1的bazel,不然会出现很多的错误无法解决。

wget https://github.com/bazelbuild/bazel/releases/download/0.18.1/bazel-0.18.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

下载tensorflow工程代码

git clone https://github.com/tensorflow/tensorflow.git

编译转换工具

cd tensorflow/
bazel build tensorflow/python/tools:freeze_graph
bazel build tensorflow/contrib/lite/toco:toco

生成tflite_graph.pb文件

cd models/research/object_detection
python export_tflite_ssd_graph.py \
--pipeline_config_path=data/ssd_mobilenet_v1_coco.config \
--trained_checkpoint_prefix=data/training/model.ckpt-28189 \
--output_directory=data/output \
--add_postprocessing_op=true

利用bazel生成tflite文件

bazel-bin/tensorflow/contrib/lite/toco/toco \
--input_file=tflite_graph.pb \
--output_file=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=QUANTIZED_UINT8 \
--mean_values=128 \
--std_values=128 \
--change_concat_input_ranges=false \
--default_ranges_min=0 \
--default_ranges_max=6 \
--allow_custom_ops

在Android上测试

在下面的目录中有tensorflow lite的例子,可以替换原来的detect.tflite文件,修改对应的coco_labels_list.txt文件,建议改成不一样的名称,修改代码,不然运行的时候,detect.tflitecoco_labels_list.txt会重新下载,又被覆盖掉了

 
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,115
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,587
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,433
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,204
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,839
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,925