码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • openvino 将onnx转为IR并进行int8量化


    openvino 将onnx转为IR并进行int8量化

    • 环境
    • 安装环境
    • 编译 mo
      • 下载 openvino
      • 编译 mo
    • onnx 转为 IR
    • IR 模型量化为 int8
    • 参考

    环境

    - Ubuntu 22.04
    - python 3.10
    
    • 1
    • 2

    安装环境

    sudo apt-get update
    sudo apt-get upgrade
    sudo apt-get install python3-venv build-essential python3-dev git-all -y
    sudo apt-get install intel-opencl-icd -y
    
    • 1
    • 2
    • 3
    • 4

    编译 mo

    下载 openvino

    git clone https://github.com/openvinotoolkit/openvino
    
    • 1

    编译 mo

    cd openvino/tools
    python3 -m pip install mo
    
    • 1
    • 2

    编译成功输出如下信息:

    Collecting mo
      Downloading mo-0.3.0-py2.py3-none-any.whl (12 kB)
    Requirement already satisfied: PyYAML in /usr/local/lib/python3.10/dist-packages (from mo) (6.0)
    Collecting colorama (from mo)
      Downloading colorama-0.4.6-py2.py3-none-any.whl (25 kB)
    Requirement already satisfied: toml in /usr/local/lib/python3.10/dist-packages (from mo) (0.10.2)
    Installing collected packages: colorama, mo
    Successfully installed colorama-0.4.6 mo-0.3.0
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    安装

    pip install openvino-dev
    
    • 1

    查看帮助

    mo -h
    
    • 1

    onnx 转为 IR

    mo --input_model onnx/model.onnx --compress_to_fp16 --output_dir ir_model
    
    • 1

    这里压缩为fp16

    输出信息:

    [ INFO ] Generated IR will be compressed to FP16. If you get lower accuracy, please consider disabling compression explicitly by adding argument --compress_to_fp16=False.
    Find more information about compression to FP16 at https://docs.openvino.ai/2023.0/openvino_docs_MO_DG_FP16_Compression.html
    [ INFO ] The model was converted to IR v11, the latest model format that corresponds to the source DL framework input/output format. While IR v11 is backwards compatible with OpenVINO Inference Engine API v1.0, please use API v2.0 (as of 2022.1) to take advantage of the latest improvements in IR v11.
    Find more information about API v2.0 and IR v11 at https://docs.openvino.ai/2023.0/openvino_2_0_transition_guide.html
    [ SUCCESS ] Generated IR version 11 model.
    [ SUCCESS ] XML file: /workspace/bert/ir_model/model.xml
    [ SUCCESS ] BIN file: /workspace/bert/ir_model/model.bin
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    转换成功了!

    输出文件对比:

    # ls -lh ir_model/
    total 321M
    -rw-r--r-- 1 root root 319M Sep 22 11:27 model.bin
    -rw-r--r-- 1 root root 1.8M Sep 22 11:27 model.xml
    
    # ls -lh onnx/
    total 640M
    -rw-r--r-- 1 root root 640M Sep 21 20:23 model.onnx
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    IR 模型量化为 int8

    编译 Post-Training Optimization Tool

    cd openvino/tools/pot/
    python3 setup.py install
    
    • 1
    • 2

    bert模型量化步骤参考:
    https://github.com/openvinotoolkit/openvino_notebooks/tree/main/notebooks/105-language-quantize-bert

    Quantization of Image Classification model参考:
    https://github.com/openvinotoolkit/openvino_notebooks/tree/main/notebooks/301-tensorflow-training-openvino

    参考

    1. https://github.com/openvinotoolkit/openvino_notebooks#-installation-guide
    2. https://docs.openvino.ai/2022.3/notebooks/102-pytorch-onnx-to-openvino-with-output.html
    3. https://github.com/openvinotoolkit/openvino/tree/master/tools/mo
    4. https://github.com/openvinotoolkit/openvino
    5. https://github.com/openvinotoolkit/openvino/tree/master/tools/pot
  • 相关阅读:
    引用与指针及数组指针与指针数组的区别实践
    .NET 扩展官方 Logger 实现将日志保存到本地文件
    wifi管理软件 WiFi Signal mac中文介绍
    PX4模块设计之十五:PX4 Log设计
    现代企业杂志现代企业杂志社现代企业编辑部2022年第8期目录
    树莓派环境配置
    pytorch --反向传播和优化器
    (26)Blender源码分析之顶层菜单的关于菜单
    双非一本 大一 就业方向选择
    基于双级阈值及过零率的语音激活检测(VAD)
  • 原文地址:https://blog.csdn.net/zengNLP/article/details/133197334
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号