> For the complete documentation index, see [llms.txt](https://1684.gitbook.io/bmnnsdk2-1684-2-0-1/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://1684.gitbook.io/bmnnsdk2-1684-2-0-1/int8-umodel-greater-than-int8-bmodel-path_d.md).

# INT8 Umodel转换INT8 Bmodel

​(在最终生成部署文件bmodel之前，可以参考#5精度测试，检查量化精度是否正常，或者使用bmodel查看最终的推理结果) Int8umodel作为一个临时中间存在形式，需要进一步转换为可以在bitmain AI平台执行的bmodel，可以看作int8umodel的部署操作。

此流程会使用SDK提供的BMNETU工具，使用步骤2中的输出作为输入，方便快捷转换，具体使用命令介绍： BMNETU是针对BM1684的UFW(Unified Framework)模型编译器，可将某网络的umodel(Unified Model)和 prototxt编译成BMRuntime所需要的文件。而且在编译的同时，支持每一层的NPU模型计算结 果和CPU的计算结果进行对比，保证正确性。

Command name: bmnetu - BMNet compiler command for UFW model

```
      /path/to/bmnetu -model=<path> \
     　　              -weight=<path> \
     　　              -shapes=<string> \
     　　              -net_name=<name> \
     　　              -opt=<value> \
     　　              -dyn=<bool> \
     　　              -prec=<string> \
     　　              -outdir=<path> \
     　　              -cmp=<bool> \
     　　              -mode=<string>
```

通过shell脚本方式可以运行，参数介绍：

| args      | type   | Description                                                                                                                                     |
| --------- | ------ | ----------------------------------------------------------------------------------------------------------------------------------------------- |
| model     | String | Necessary. UFW prototxt path                                                                                                                    |
| weight    | string | Necessary. Umodel(weight) path                                                                                                                  |
| shapes    | string | Optional. Shapes of all inputs, default use the shape in prototxt, format \[x,x,x,x],\[x,x]…, these correspond to inputs one by one in sequence |
| net\_name | string | Optional. Name of the network, default use the name in prototxt                                                                                 |
| opt       | int    | Optional. Optimization level. Option: 0, 1, 2, default 2.                                                                                       |
| dyn       | bool   | Optional. Use dynamic compilation, default false.                                                                                               |
| outdir    | string | Necessary. Output directory                                                                                                                     |
| prec      | string | Optional. Data type of Umodel. Option: FP32, INT8. default FP32.                                                                                |
| cmp       | bool   | Optional.Check result during compilation. Default: true                                                                                         |
| mode      | string | Optional. Set bmnetc mode. Option: compile, GenUmodel. Default: compile.                                                                        |

* 在SDK中的SSD示例中，具体转换指令如下：

```
     function gen_int8bmodel()
     {
        mkdir -p int8model
        bmnetu -model=ssd300_deploy_int8_unique_top.prototxt \
             -weight=ssd300.int8umodel \
             -max_n=1 \
             -prec=INT8 \
             -dyn=0 \
             -cmp=1 \
             -target=BM1684 \
             -outdir=./int8model
     }
```

* 最终会在较长运行时间后生成目标bmodel：

```
int8model
├── compilation_1.bmodel //n,c,h,w (1,3,300,300)
├── compilation_4.bmodel //n,c,h,w (4,3,300,300)
out/
├── int8_ssd300.bmodel  //compilation_1.bmodel 和 compilation_4.bmodel进行combine后的bmodel
```

可以基于此bmodel在soc/cmodel下做推理。

## **精度测试**

在生成新的int8 bmodel后，网络可能需要验证精度损失，SDK提供不同类型网络的精度比对方式。 1.通过图形界面检查精度差异，参考view\_demo. 2.分类网络，通过修改网络输出层添加top-k，参考classify\_demo. 3.检测网络，通过ufw测试特定图片，与fp32网络比对，参考detect\_demo.
