栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

ubuntu16.04中tensorflow转换为tflite模型的方式

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

ubuntu16.04中tensorflow转换为tflite模型的方式

  1. 压缩模型需要从源代码编译,需要安装bazel  
  2. 官网的安装方式:https://docs.bazel.build/versions/master/install-ubuntu.html  
  3. 这里采用Installing using binary installer方式,即使用sh文件安装  
  4.   
  5. sudo apt-get install pkg-config zip g++ zlib1g-dev unzip python  
  6.   
  7. wget https://github.com/bazelbuild/bazel/releases/download/0.21.0/bazel-0.21.0-installer-linux-x86_64.sh  
  8.   
  9. sudo chmod +x bazel-0.21.0-installer-linux-x86_64.sh  
  10.   
  11. ./bazel-0.21.0-installer-linux-x86_64.sh --user  
  12.   
  13. 设置环境变量:  
  14. sudo gedit ~/.bashrc,最后一行加上  
  15.   
  16. export PATH="$PATH:$HOME/bin"  
  17.   
  18. 然后使之生效:source ~/.bashrc  
  19.   
  20. 下载最新的TensorFlow库  
  21. git clone https://github.com/tensorflow/tensorflow.git  
  22. cd ./tensorflow  
  23. 编译graph_transforms模块,需要等待一段时间,编译很耗费CPU资源和时间  
  24. bazel build tensorflow/lite/toco:toco  
  25.   
  26. 从链接中下载预训练模型,然后使用object detection的官方训练代码训练网络,http://download.tensorflow.org/models/object_detection/ssdlite_mobilenet_v2_coco_2018_05_09.tar.gz  
  27. 使用ssdlite训练生成的模型,使用research/object_detection/export_tflite_ssd_graph.py转换为tflite_graph.pb、tflite_graph.pbtxt。  
  28.   
  29. 然后在tensorflow/tensorflow文件夹中使用命令,将其转换为detect.tflite文件。  
  30. 转换为UINT8的方式会压缩模型  
  31. bazel run tensorflow/lite/toco:toco --  --input_file=/home/shzy/disks/project/fingerdtpaper/models/data/stept_finger/model/ssdlite/tflite_graph.pb --output_file=/home/shzy/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 --allow_custom_ops --default_ranges_min=0 --default_ranges_max=255  
  32.   
  33. 转换为FLOAT的方式不会压缩模型  
  34. bazel run tensorflow/lite/toco:toco --  --input_file=/home/shzy/disks/project/fingerdtpaper/models/data/stept_finger/model/ssdlite/tflite_graph.pb --output_file=/home/shzy/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 --mean_values=128 --std_values=128 --change_concat_input_ranges=false --allow_custom_ops --default_ranges_min=0 --default_ranges_max=255  
  35.   
  36. 各种选项的解释:https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/g3doc/convert/cmdline_reference.md  
  37.   
  38. 参考的内容:https://medium.com/tensorflow/training-and-serving-a-realtime-mobile-object-detector-in-30-minutes-with-cloud-tpus-b78971cf1193  
  39.                      https://blog.csdn.net/aslily1234/article/details/84840885  
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/300512.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号