modify 说明文档

This commit is contained in:
chakcy 2026-02-03 22:10:25 +08:00
parent f17ef8b38a
commit 7880c9e15b
2 changed files with 180 additions and 0 deletions

180
README.md
View File

@ -282,3 +282,183 @@ python -m sophon_chakcy.build --verbose
├── my_detector
└── faster_rcnn
```
## YOLOv8 示例
### 配置文件
`./config.json` 文件中添加对应的配置
```json
{
"file_system": {
"type": "vfs"
},
"vfs": {
"file_path": "./application.svfs"
},
"model_map": {
"yolo_example": {
"name": "yolo_example", # 插件名称
"module": "YOLOv8.yolov8_detector", # Detector 类模块位置
"config": "resources/yolov8_config.json" # 插件配置路径
}
}
}
```
编写插件配置 `resources/yolov8_config.json`
```json
{
"bmodel_path": "resources/yolov8s_int8_1b.bmodel", # 模型路径
"classes": [ # 检测类型
...
],
"colors": [ # 边框颜色
[56, 0, 255],
...
]
}
```
将模型放置在配置对应的路径下YOLOv8 插件代码可参考 `./YOLOv8` (注意需实现配置类和 Detector 类,且 Detector 所在路径需与 config.json 中的配置保持一致)
### 测试
执行 download.sh 脚本下载测试图片
```bash
./scripts/download.sh
```
执行测试
```bash
python main.py --name yolo_example --input ./resources/datasets/test/3.jpg
```
结果
```text
[BMRT][bmcpu_setup:406] INFO:cpu_lib 'libcpuop.so' is loaded.
bmcpu init: skip cpu_user_defined
open usercpu.so, init user_cpu_init
[BMRT][load_bmodel:1084] INFO:Loading bmodel from [resources/yolov8s_int8_1b.bmodel]. Thanks for your patience...
[BMRT][load_bmodel:1023] INFO:pre net num: 0, load net num: 1
加载模型: resources/yolov8s_int8_1b.bmodel
模型信息:
输入形状: [1, 3, 640, 640]
输入类型: Dtype.BM_FLOAT32
colors数量: 81
classes类别数: 81
处理图像: ./resources/datasets/test/3.jpg
Open /dev/jpu successfully, device index = 0, jpu fd = 33, vpp fd = 34
图像大小: 854x480
原始检测数量: 11
过滤后数量 (置信度 > 0.25): 11
绘制 11 个检测结果:
--------------------------------------------------------------------------------
检测 1: person | 置信度: 0.9176 | 位置: [ 74, 163, 209, 422] | 大小: 135x 259 | 颜色: [226, 255, 0]
检测 2: person | 置信度: 0.9176 | 位置: [ 728, 142, 849, 472] | 大小: 121x 330 | 颜色: [226, 255, 0]
检测 3: person | 置信度: 0.8510 | 位置: [ 342, 181, 404, 314] | 大小: 62x 133 | 颜色: [226, 255, 0]
检测 4: person | 置信度: 0.8510 | 位置: [ 539, 152, 640, 428] | 大小: 101x 276 | 颜色: [226, 255, 0]
检测 5: skis | 置信度: 0.8196 | 位置: [ 99, 384, 221, 464] | 大小: 122x 80 | 颜色: [132, 0, 255]
检测 6: person | 置信度: 0.8196 | 位置: [ 494, 172, 571, 379] | 大小: 77x 207 | 颜色: [226, 255, 0]
检测 7: skis | 置信度: 0.6078 | 位置: [ 450, 403, 728, 447] | 大小: 278x 44 | 颜色: [132, 0, 255]
检测 8: skis | 置信度: 0.4471 | 位置: [ 439, 370, 588, 403] | 大小: 149x 33 | 颜色: [132, 0, 255]
检测 9: skis | 置信度: 0.3922 | 位置: [ 365, 311, 404, 322] | 大小: 39x 11 | 颜色: [132, 0, 255]
检测 10: car | 置信度: 0.2941 | 位置: [ 1, 215, 33, 248] | 大小: 32x 33 | 颜色: [0, 37, 255]
检测 11: skis | 置信度: 0.2510 | 位置: [ 364, 307, 404, 322] | 大小: 40x 15 | 颜色: [132, 0, 255]
--------------------------------------------------------------------------------
检测结果已保存到: ./detection_results/detected_3.jpg
```
![detected_3.jpg](./images/detected_3.jpg)
### 打包
```bash
python -m sophon_chakcy.build
```
```
清理旧的构建目录: build
开始构建...
配置文件加载成功
VFS初始化成功: application.svfs
模块打包器初始化成功: plugins.mbank
添加文件失败 config.json: UNIQUE constraint failed: files.path
添加文件: config.json
文件大小: 0.00 MB
数据库文件: application.svfs
导出文件失败 config.json: [Errno 2] No such file or directory: ''
已保存到: config.json
已保存到: application.svfs
配置文件已添加到VFS
打包模块: YOLOv8.yolov8_detector
打包包: YOLOv8 (来自: YOLOv8/__init__.py)
打包模块: YOLOv8.yolov8_detector (来自: YOLOv8/yolov8_detector.py)
打包模块: YOLOv8.postprocess_numpy (来自: YOLOv8/postprocess_numpy.py)
添加文件失败 resources/yolov8_config.json: UNIQUE constraint failed: files.path
添加文件: resources/yolov8_config.json
文件大小: 0.01 MB
数据库文件: application.svfs
导出成功: resources/yolov8_config.json -> resources/yolov8_config.json
已保存到: resources/yolov8_config.json
已保存到: application.svfs
添加文件失败 resources/yolov8s_int8_1b.bmodel: UNIQUE constraint failed: files.path
添加文件: resources/yolov8s_int8_1b.bmodel
文件大小: 11.44 MB
数据库文件: application.svfs
导出成功: resources/yolov8s_int8_1b.bmodel -> resources/yolov8s_int8_1b.bmodel
已保存到: resources/yolov8s_int8_1b.bmodel
已保存到: application.svfs
添加模型文件: resources/yolov8s_int8_1b.bmodel
VFS内容:
FILE: config.json (313 bytes)
FILE: resources/yolov8_config.json (7178 bytes)
FILE: resources/yolov8s_int8_1b.bmodel (11993088 bytes)
复制文件到构建目录...
复制: public/main.py
复制: application.svfs
复制: plugins.mbank
构建成功完成! 输出目录: build
主程序: build/main.py
VFS文件: build/application.svfs
模块库: build/plugins.mbank
```
./build
```
部署目录/
├── main.py # 主程序使用VFS和模块库
├── application.svfs # 虚拟文件系统(存储配置文件和模型)
└── plugins.mbank # Python模块库
```
## 部署
方法一:构建 whl 并在生成环境中安装
```bash
uv build
ls dist
```
```text
(sophon-chakcy) linaro@bm1684:/data/sophon_chakcy$ uv build
Building source distribution...
Building wheel from source distribution...
Successfully built dist/sophon_chakcy-0.1.0.tar.gz
Successfully built dist/sophon_chakcy-0.1.0-py3-none-any.whl
(sophon-chakcy) linaro@bm1684:/data/sophon_chakcy$ ls dist
sophon_chakcy-0.1.0-py3-none-any.whl sophon_chakcy-0.1.0.tar.gz
(sophon-chakcy) linaro@bm1684:/data/sophon_chakcy$
```
方法二:复制 src/sophon_chakcy 到项目根路径

BIN
images/detected_3.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB