> For the complete documentation index, see [llms.txt](https://sophgo-doc.gitbook.io/bmnnsdk2-bm1684/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sophgo-doc.gitbook.io/bmnnsdk2-bm1684/model-convert/fp32-bmodel/darknet.md).

# 3.2.5 编译 Darknet 模型

BMNETD 是针对 Darknet 的模型编译器，可将某网络的 weight 和 cfg 编译成 BMRuntime 所需要 的文件 (目前只支持 yolo)。而且在编译的同时，支持每一层的 NPU 模型计算结果都会和 CPU 的计算结果进行对 比，保证正确性。

bmnetd的使用例程参见${BMNNSDK}/examples/nntc/bmnetd。

{% hint style="info" %}
**Darknet模型转换注意事项**

cfg 文件中batch/subvision 要大于转换脚本中设置的输入shape的batch size。&#x20;
{% endhint %}

* 命令行形式：

```bash
/path/to/bmnetd [--model=<path>] \
                [--weight=<path>] \
                [--shapes=<string>] \ 
                [--net_name=<name>] \ 
                [--opt=<value>] \ 
                [--dyn=<bool>] \ 
                [--outdir=<path>] \ 
                [--target=<name>] \ 
                [--cmp=<bool>] \ 
                [--mode=<string>] \ 
                [--enable_profile=<bool>]
```

参数介绍：

<table><thead><tr><th width="205.66666666666666">args</th><th>type</th><th>Description</th></tr></thead><tbody><tr><td>model</td><td>string</td><td><strong>Necessary.</strong> Darknet cfg path</td></tr><tr><td>weights</td><td>string</td><td><strong>Necessary.</strong>Darknet weight path</td></tr><tr><td>shapes</td><td>string</td><td><strong>Optional.</strong> 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</td></tr><tr><td>net_name</td><td>string</td><td><strong>Optional.</strong> Name of the network, default use cfg path</td></tr><tr><td>opt</td><td>int</td><td><strong>Optional.</strong> Optimization level. Option: 0, 1, 2, default 2.</td></tr><tr><td>dyn</td><td>bool</td><td><strong>Optional.</strong> Use dynamic compilation, default false.</td></tr><tr><td>outdir</td><td>string</td><td><strong>Necessary.</strong> Output directory</td></tr><tr><td>target</td><td>string</td><td><strong>Necessary.</strong> Option: BM1682, BM1684; default: BM1682</td></tr><tr><td>cmp</td><td>bool</td><td><strong>Optional.</strong>Check result during compilation. Default: true</td></tr><tr><td>mode</td><td>string</td><td><strong>Optional.</strong> Set bmnetc mode. Option: compile, GenUmodel. Default: compile.</td></tr><tr><td>enable_profile</td><td>bool</td><td><strong>Optional.</strong> Enable profile log. Default: fals</td></tr><tr><td>log_dir</td><td>string</td><td><strong>Optional.</strong> Specify the log directory Default: “”</td></tr><tr><td>v</td><td>string</td><td><strong>Optional.</strong>Set log verbose level. Default: 0 (0: FATAL, 1: ERROR, 2: WARNING, 3: INFO, 4: DEBUG).</td></tr><tr><td>dump_ref</td><td>bool</td><td><strong>Optional.</strong>Enable dump input&#x26;output ref data when compile without compare. Default: false.</td></tr></tbody></table>

* Python模式：

```python
import bmnetd
## compile fp32 model
bmnetd.compile(
    model = "/path/to/cfg", ## Necessary
    weight = "/path/to/weight", ## Necessary
    outdir = "xxx", ## Necessary
    target = "BM1684", ## Necessary
    net_name = "name", ## optional, if not set, default use the path of cfg
    shapes = [[x,x,x,x], [x,x,x]], ## optional, if not set, default use shape in weights
    opt = 2, ## optional, if not set, default equal to 2
    dyn = False, ## optional, if not set, default equal to False
    cmp = True, ## optional, if not set, default equal to True
    enable_profile = False ## optional, if not set, default equal to False
)
```

bmnetd若成功，输出的 log 最后会看到以下信息：

```bash
######################################
# Store bmodel of BMCompiler.
######################################
```

bmnetd成功后，将在指定的文件夹中生成一个compilation.bmodel的文件，该文件则是转换成功的 bmodel，用户可以重命名。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://sophgo-doc.gitbook.io/bmnnsdk2-bm1684/model-convert/fp32-bmodel/darknet.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
