915|0

47

帖子

5

TA的资源

一粒金砂(中级)

楼主
 

爱芯元智AX650N部署yolov5s 自定义模型 [复制链接]

> 本博客将向你展示零基础一步步的部署好自己的yolov5s模型(博主展示的是安全帽模型),利用yolov5 官方的代码工具导出onnx模型,并通过onnxsim自带的工具精简网络结构,导出子图,为了Pulsar2 工具进行处理模型做准备。

获得自定义训练得到的yolov5s onnx模型

准备自定义数据集(博主用的是VOC数据集)

  • 数据集目录结构如下:
    1. └─VOC2028: 自定义数据集
    2. ├─Annotations 存放的是数据集标签文件,xml格式
    3. ├─ImageSets 数据集的划分文件
    4. │└─Main
    5. ├─JPEGImages 存放的是数据集图片
  • 分割数据集

在split_train_val.py文件路径下执行python3 split_train_val.py会得到一下目录结构:

  1. └─VOC2028: 自定义数据集
  2. ├─Annotations 存放的是数据集标签文件,xml格式
  3. ├─ImageSets 数据集的划分文件
  4. │└─Main test.txt
  5. └─test.txt
  6. └─train.txt
  7. └─val.txt
  8. ├─JPEGImages 存放的是数据集图片
  9. ├─split_train_val.py 分割数据集的py文件

split_train_val.py文件代码如下

  1. # -*- coding: utf-8 -*-
  2. """
  3. Author:dragonforward
  4. 简介:分训练集、验证集和测试集,按照 8:1:1 的比例来分,训练集8,验证集1,测试集1
  5. """
  6. import os
  7. import random
  8. import argparse
  9. parser = argparse.ArgumentParser()
  10. # xml文件的地址,根据自己的数据进行修改 xml一般存放在Annotations下
  11. parser.add_argument('--xml_path', default='Annotations/', type=str, help='input xml label path')
  12. # 数据集的划分,地址选择自己数据下的ImageSets/Main
  13. parser.add_argument('--txt_path', default='ImageSets/Main/', type=str, help='output txt label path')
  14. opt = parser.parse_args()
  15. train_percent = 0.8# 训练集所占比例
  16. val_percent = 0.1 # 验证集所占比例
  17. test_persent = 0.1 # 测试集所占比例
  18. xmlfilepath = opt.xml_path
  19. txtsavepath = opt.txt_path
  20. total_xml = os.listdir(xmlfilepath)
  21. if not os.path.exists(txtsavepath):
  22. os.makedirs(txtsavepath)
  23. num = len(total_xml)
  24. list = list(range(num))
  25. t_train = int(num * train_percent)
  26. t_val = int(num * val_percent)
  27. train = random.sample(list, t_train)
  28. num1 = len(train)
  29. for i in range(num1):
  30. list.remove(train[i])
  31. val_test = [i for i in list if not i in train]
  32. val = random.sample(val_test, t_val)
  33. num2 = len(val)
  34. for i in range(num2):
  35. list.remove(val[i])
  36. file_train = open(txtsavepath + '/train.txt', 'w')
  37. file_val = open(txtsavepath + '/val.txt', 'w')
  38. file_test = open(txtsavepath + '/test.txt', 'w')
  39. for i in train:
  40. name = total_xml[i][:-4] + '\n'
  41. file_train.write(name)
  42. for i in val:
  43. name = total_xml[i][:-4] + '\n'
  44. file_val.write(name)
  45. for i in list:
  46. name = total_xml[i][:-4] + '\n'
  47. file_test.write(name)
  48. file_train.close()
  49. file_val.close()
  50. file_test.close()
  • voc转label得到label文件

目录结构如下:

  1. └─VOC2028: 自定义数据集
  2. ├─Annotations 存放的是数据集标签文件,xml格式
  3. ├─ImageSets 数据集的划分文件
  4. │└─Main
  5. ├─JPEGImages 存放的是数据集图片
  6. └─labels yolov5将此文件夹当作训练的标注文件夹
  7. └─voc_label.py

voc_label.py文件代码如下

  1. # -*- coding: utf-8 -*-
  2. import xml.etree.ElementTree as ET
  3. import os
  4. sets = ['train', 'val', 'test']# 如果你的Main文件夹没有test.txt,就删掉'test'
  5. classes = ["hat", "people"] # 改成自己的类别,VOC数据集有以下20类别
  6. # classes = ["brickwork", "coil","rebar"] # 改成自己的类别,VOC数据集有以下20类别
  7. # classes = ["aeroplane", 'bicycle', 'bird', 'boat', 'bottle', 'bus', 'car', 'cat', 'chair', 'cow', 'diningtable', 'dog',
  8. # 'horse', 'motorbike', 'person', 'pottedplant', 'sheep', 'sofa', 'train', 'tvmonitor']# class names
  9. # abs_path = os.getcwd() /root/yolov5/data/voc_label.py
  10. abs_path = '/root/yolov5/data/'
  11. def convert(size, box):
  12. dw = 1. / (size[0])
  13. dh = 1. / (size[1])
  14. x = (box[0] + box[1]) / 2.0 - 1
  15. y = (box[2] + box[3]) / 2.0 - 1
  16. w = box[1] - box[0]
  17. h = box[3] - box[2]
  18. x = x * dw
  19. w = w * dw
  20. y = y * dh
  21. h = h * dh
  22. return x, y, w, h
  23. def convert_annotation(image_id):
  24. in_file = open(abs_path + '/VOC2028/Annotations/%s.xml' % (image_id), encoding='UTF-8')
  25. out_file = open(abs_path + '/VOC2028/labels/%s.txt' % (image_id), 'w')
  26. tree = ET.parse(in_file)
  27. root = tree.getroot()
  28. size = root.find('size')
  29. w = int(size.find('width').text)
  30. h = int(size.find('height').text)
  31. for obj in root.iter('object'):
  32. difficult = obj.find('difficult').text
  33. # difficult = obj.find('Difficult').text
  34. cls = obj.find('name').text
  35. if cls not in classes or int(difficult) == 1:
  36. continue
  37. cls_id = classes.index(cls)
  38. xmlbox = obj.find('bndbox')
  39. b = (float(xmlbox.find('xmin').text), float(xmlbox.find('xmax').text), float(xmlbox.find('ymin').text),
  40. float(xmlbox.find('ymax').text))
  41. b1, b2, b3, b4 = b
  42. # 标注越界修正
  43. if b2 > w:
  44. b2 = w
  45. if b4 > h:
  46. b4 = h
  47. b = (b1, b2, b3, b4)
  48. bb = convert((w, h), b)
  49. out_file.write(str(cls_id) + " " + " ".join([str(a) for a in bb]) + '\n')
  50. for image_set in sets:
  51. if not os.path.exists(abs_path + '/VOC2028/labels/'):
  52. os.makedirs(abs_path + '/VOC2028/labels/')
  53. image_ids = open(abs_path + '/VOC2028/ImageSets/Main/%s.txt' % (image_set)).read().strip().split()
  54. list_file = open(abs_path + '/VOC2028/%s.txt' % (image_set), 'w')
  55. for image_id in image_ids:
  56. list_file.write(abs_path + '/VOC2028/JPEGImages/%s.jpg\n' % (image_id))# 要么自己补全路径,只写一半可能会报错
  57. convert_annotation(image_id)
  58. list_file.close()

picture 1

训练模型

  • 配置环境
    1. git clone https://github.com/ultralytics/yolov5
    2. cd yolov5
    3. pip install -r requirements.txt
    4. pip install onnx
  • 下载预训练权重(博主尝试了v7.0的和v6.0的pt都可以)

    1. https://github.com/ultralytics/yolov5/releases/download/v7.0/yolov5s.pt

    picture 0

  • 训练(博主使用的是学校的集群进行训练)

  1. python3 train.py --weights weights/yolov5s.pt --cfg models/yolov5s.yaml --data data/safthat.yaml --epochs 150 --batch-size 16 --multi-scale --device 0

picture 2

  1. python3 detect.py --source /root/yolov5/data/images/000000.jpg --weights /root/yolov5/runs/train/exp13/weights/best.pt --conf-thres 0.25

picture 3

  • 导出onnx模型,并通过onnxsim自带的工具精简网络结构,导出子图
  1. python3 export.py --weightsyolov5s_hat.pt --include onnx
  2. pip install onnx-simplifier
  3. python3 -m onnxsim yolov5s_hat.onnx yolov5s_hat_sub.onnx

picture 4

模型查看通过网址输入netron.app查看三个输出:

picture 8

查看官方给的yolov5s.json文件:

  1. {
  2. "model_type": "ONNX",
  3. "npu_mode": "NPU1",
  4. "quant": {
  5. "input_configs": [
  6. {
  7. "tensor_name": "images",
  8. "calibration_dataset": "./dataset/calibration_dataset.tar.gz",
  9. "calibration_size": 4,
  10. "calibration_mean": [0, 0, 0],
  11. "calibration_std": [255.0, 255.0, 255.0]
  12. }
  13. ],
  14. "calibration_method": "MinMax",
  15. "precision_analysis": false
  16. },
  17. "input_processors": [
  18. {
  19. "tensor_name": "images",
  20. "tensor_format": "BGR",
  21. "src_format": "BGR",
  22. "src_dtype": "U8",
  23. "src_layout": "NHWC"
  24. }
  25. ],
  26. "output_processors": [
  27. {
  28. "tensor_name": "326",
  29. "dst_perm": [0, 2, 3, 1]
  30. },
  31. {
  32. "tensor_name": "370",
  33. "dst_perm": [0, 2, 3, 1]
  34. },
  35. {
  36. "tensor_name": "414",
  37. "dst_perm": [0, 2, 3, 1]
  38. }
  39. ],
  40. "compiler": {
  41. "check": 0
  42. }
  43. }

output_processors给的326,370,414

根据秋水大佬博客的导出子图文件修改得到适应pulsar2工具的onnx文件:

  1. import onnx
  2. input_path = "yolov5s_hat-sim.onnx"
  3. output_path = "yolov5s_hat_sub.onnx"
  4. input_names = ["images"]
  5. output_names = ["326","370","414"]
  6. onnx.utils.extract_model(input_path, output_path, input_names, output_names)

问题记录:
(1)导出子图很关键
   由于之前对深度学习知识了解很少,才知道子图,如果执行使用yolov5s_hat_sub.onnx,在Pulsar2工具中进行量化的话,会生成axmodel但是是无法执行了,通过o0圏圏蟲0o大佬给的模型对比网络结构和秋水大佬的ax620a部署yolov5博客才明白自己问题出现在哪里

如果你没处理导出子图得到的图会是这样:
picture 5

正确量化后的yolov5s图:

官方的yolov5s模型:

picture 6
博主的正确的axmodel:
picture 7

其中数字不同255和21的原因(秋水大佬博客有讲):
该数字为(模型训练的类别+5)*3,博主类别为2类,所以就是21

模型转化(关键)

安装docker环境(已安装过的可以跳过)

  1. 安装docker依赖的基础软件
  2. sudo apt-get update
  3. sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
  4. 添加官方来源
  5. curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
  6. sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
  7. 安装 docker
  8. sudo apt-get update
  9. sudo apt-get install docker-ce docker-ce-cli containerd.io

pulsar2工具模型转化以及仿真运行

  • 下载pulsar2工具(博主使用的是1.9)

谷歌网盘链接:

quick_start_example 文件夹
其中文件如下:

  1. configdatasetmodeloutputpulsar2-run-helper

./dataset/calibration_data.tar:添加了数据集的四张照片
config文件:

  1. {
  2. "model_type": "ONNX",
  3. "npu_mode": "NPU1",
  4. "quant": {
  5. "input_configs": [
  6. {
  7. "tensor_name": "images",
  8. "calibration_dataset": "./dataset/calibration_data.tar",
  9. "calibration_size": 4,
  10. "calibration_mean": [0, 0, 0],
  11. "calibration_std": [255.0, 255.0, 255.0]
  12. }
  13. ],
  14. "calibration_method": "MinMax",
  15. "precision_analysis": false
  16. },
  17. "input_processors": [
  18. {
  19. "tensor_name": "images",
  20. "tensor_format": "BGR",
  21. "src_format": "BGR",
  22. "src_dtype": "U8",
  23. "src_layout": "NHWC"
  24. }
  25. ],
  26. "output_processors": [
  27. {
  28. "tensor_name": "326",
  29. "dst_perm": [0, 2, 3, 1]
  30. },
  31. {
  32. "tensor_name": "370",
  33. "dst_perm": [0, 2, 3, 1]
  34. },
  35. {
  36. "tensor_name": "414",
  37. "dst_perm": [0, 2, 3, 1]
  38. }
  39. ],
  40. "compiler": {
  41. "check": 0
  42. }
  43. }
  1. (博主是直接就是root用户,如果不是root用户记得加sudo
  2. root@LAPTOP-U638FQQS:~# docker load -i ax_pulsar2_1.9_enc.tar.gz
  3. root@LAPTOP-U638FQQS:~# docker images -a
  4. REPOSITORY TAG IMAGE ID CREATED SIZE
  5. hhb4tools/rv_debian_build 1.3 08f478d17c34 7 weeks ago 2.16GB
  6. pulsar2 1.9_enc 641ba18a8da3 2 months ago 3.46GB
  7. hhb4tools/hhb 2.4.5 58df969ae05a 3 months ago 8.16GB
  8. hhb4tools/rv_ub20_build 1.4 a65456ded4f0 6 months ago 5.11GB
  9. hhb4tools/march-user-static 1.0 d9efab34da5e 7 months ago 301MB
  10. riscv64/ubuntu 22.04 8b55084b9c02 11 months ago 61.6MB
  11. riscv64/ubuntu 21.04 d0b60ed75c22 21 months ago 60.3MB
  12. root@LAPTOP-U638FQQS:~#docker run -it --net host --rm -v $PWD:/data pulsar2:1.9_enc
  13. root@1657ec5355e2:/data# pulsar2 version
  14. version: 1.9
  15. commit: c62d0b64
  16. root@1657ec5355e2:/data#
  1. 编译执行 以 yolov5s_hat_sub.onnx 为例, 执行如下 pulsar2 build 命令编译生成 compiled.axmodel:
    1. pulsar2 build --input model/yolov5s_hat_sub.onnx --output_dir output --config config/yolov5s_config.json
    博主输出信息: ``` root@1657ec5355e2:/data# pulsar2 build --input model/yolov5s_hat_sub.onnx --output_dir output --config config/yolov5s_config.json 2023-11-16 17:49:21.238 | WARNING| yamain.command.build:fill_default:320 - ignore images csc config because of src_format is AutoColorSpace or src_format and tensor_format are the same Building onnx ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:00:00 2023-11-16 17:49:22.486 | INFO | yamain.command.build:build:444 - save optimized onnx to [output/frontend/optimized.onnx] 2023-11-16 17:49:22.489 | INFO | yamain.common.util:extract_archive:21 - extract [dataset/calibration_data.tar] to [output/quant/dataset/images]...
    1. Quant Config Table
    ┏━━━━━━━━┳━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Input┃ Shape ┃ Dataset Directory ┃ Data Format ┃ Tensor Format ┃ Mean ┃ Std ┃ ┡━━━━━━━━╇━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━┩ │ images │ [1, 3, 640, 640] │ images │ Image │ BGR │ [0.0, 0.0, 0.0] │ [255.0, 255.0, 255.0] │ └────────┴──────────────────┴───────────────────┴─────────────┴───────────────┴─────────────────┴───────────────────────┘ Transformer optimize level: 0 4 File(s) Loaded. [17:49:24] AX LSTM Operation Format Pass Running ... Finished. [17:49:24] AX Set MixPrecision Pass Running ... Finished. [17:49:24] AX Refine Operation Config Pass Running ... Finished. [17:49:24] AX Reset Mul Config Pass Running ... Finished. [17:49:24] AX Tanh Operation Format Pass Running ... Finished. [17:49:24] AX Confused Op Refine Pass Running ... Finished. [17:49:24] AX Quantization Fusion Pass Running ... Finished. [17:49:24] AX Quantization Simplify Pass Running ... Finished. [17:49:24] AX Parameter Quantization Pass Running ... Finished. Calibration Progress(Phase 1): 100%|███████████████████████████████████████████████████████████████████████████████| 4/4 [00:01<00:00,2.16it/s] Finished. [17:49:26] AX Passive Parameter Quantization Running ...Finished. [17:49:26] AX Parameter Baking Pass Running ... Finished. [17:49:26] AX Refine Int Parameter Pass Running ... Finished. [17:49:26] AX Refine Weight Parameter Pass Running ... Finished.

--------- Network Snapshot ---------
Num of Op: [142]
Num of Quantized Op: [142]
Num of Variable: [267]
Num of Quantized Var: [267]
------- Quantization Snapshot ------
Num of Quant Config: [430]
BAKED: [60]
OVERLAPPED: [168]
ACTIVATED: [138]
SOI: [4]
PASSIVE_BAKED: [60]
Network Quantization Finished.
quant.axmodel export success: output/quant/quant_axmodel.onnx
===>export input/output data to folder: output/quant/debug/test_data_set_0
Building native ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:00:00
2023-11-16 17:49:28.704 | WARNING| yamain.command.load_model:pre_process:454 - preprocess tensor [images]
2023-11-16 17:49:28.704 | INFO | yamain.command.load_model:pre_process:456 - tensor: images, (1, 640, 640, 3), U8
2023-11-16 17:49:28.705 | INFO | yamain.command.load_model:pre_process:456 - op: op:pre_dequant_1, AxDequantizeLinear, {'const_inputs': {'x_zeropoint': array(0, dtype=int32), 'x_scale': array(1., dtype=float32)}, 'output_dtype': <class 'numpy.float32'>, 'quant_method': 0}
2023-11-16 17:49:28.705 | INFO | yamain.command.load_model:pre_process:456 - tensor: tensor:pre_norm_1, (1, 640, 640, 3), FP32
2023-11-16 17:49:28.705 | INFO | yamain.command.load_model:pre_process:456 - op: op:pre_norm_1, AxNormalize, {'dim': 3, 'mean': [0.0, 0.0, 0.0], 'std': [255.0, 255.0, 255.0]}
2023-11-16 17:49:28.705 | INFO | yamain.command.load_model:pre_process:456 - tensor: tensor:pre_transpose_1, (1, 640, 640, 3), FP32
2023-11-16 17:49:28.705 | INFO | yamain.command.load_model:pre_process:456 - op: op:pre_transpose_1, AxTranspose, {'perm': [0, 3, 1, 2]}
2023-11-16 17:49:28.705 | WARNING| yamain.command.load_model:post_process:475 - postprocess tensor [326]
2023-11-16 17:49:28.705 | INFO | yamain.command.load_model:handle_postprocess:473 - op: op:post_transpose_1, AxTranspose
2023-11-16 17:49:28.705 | WARNING| yamain.command.load_model:post_process:475 - postprocess tensor [370]
2023-11-16 17:49:28.706 | INFO | yamain.command.load_model:handle_postprocess:473 - op: op:post_transpose_2, AxTranspose
2023-11-16 17:49:28.706 | WARNING| yamain.command.load_model:post_process:475 - postprocess tensor [414]
2023-11-16 17:49:28.706 | INFO | yamain.command.load_model:handle_postprocess:473 - op: op:post_transpose_3, AxTranspose
tiling op... ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 241/241 0:00:00
new_ddr_tensor = []
:186: RuntimeWarning: divide by zero encountered in divide
:187: RuntimeWarning: invalid value encountered in divide
build op... ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1177/1177 0:00:04
add ddr swap... ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1141/1141 0:00:00
calc input dependencies... ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1437/1437 0:00:00
calc output dependencies... ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1437/1437 0:00:00
assign eu heuristic ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1437/1437 0:00:00
assign eu onepass ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1437/1437 0:00:00
assign eu greedy ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1437/1437 0:00:00
2023-11-16 17:49:34.720 | INFO | yasched.test_onepass:results2model:2004 - max_cycle = 4,846,471
2023-11-16 17:49:35.349 | INFO | yamain.command.build:compile_npu_subgraph:1076 - QuantAxModel macs: 7,881,318,400
2023-11-16 17:49:35.352 | INFO | yamain.command.build:compile_npu_subgraph:1084 - use random data as gt input: images, uint8, (1, 640, 640, 3)
2023-11-16 17:49:38.687 | INFO | yamain.command.build:compile_ptq_model:1003 - fuse 1 subgraph(s)
root@1657ec5355e2:/data#

  1. 2. 模型仿真运行

cp output/compiled.axmodel pulsar2-run-helper/models/yolov5s_hat.axmodel
输入数据准备
python3 cli_detection.py --pre_processing --image_path sim_images/000032.jpg --axmodel_path models/yolov5s_hat.axmodel --intermediate_path sim_inputs/0
输出信息:
root@1657ec5355e2:/data/pulsar2-run-helper# python3 cli_detection.py --pre_processing --image_path sim_images/000032.jpg --axmodel_path models/yolov5s_hat.axmodel --intermediate_path sim_inputs/0
[I] Write [images] to 'sim_inputs/0/images.bin' successfully.
仿真模型推理
pulsar2 run --model models/yolov5s_hat.axmodel --input_dir sim_inputs --output_dir sim_outputs --list list.txt
输出信息:
root@1657ec5355e2:/data/pulsar2-run-helper# pulsar2 run --model models/yolov5s_hat.axmodel --input_dir sim_inputs --output_dir sim_outputs --list list.txt
Building native ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:00:00

[0] start
write [326] to [sim_outputs/0/326.bin] successfully
write [370] to [sim_outputs/0/370.bin] successfully
write [414] to [sim_outputs/0/414.bin] successfully
[0] finish
输出数据处理(记得指定图片路径)
python3 cli_detection.py --post_processing --image_path sim_images/000032.jpg --axmodel_path models/yolov5s_hat.axmodel --intermediate_path sim_outputs/0
输出信息:
root@1657ec5355e2:/data/pulsar2-run-helper# python3 cli_detection.py --post_processing --image_path sim_images/000032.jpg --axmodel_path models/yolov5s_hat.axmodel --intermediate_path sim_outputs/0
[I] Number of detected objects: 7
[I]0: 94.59%, [972, 224, 1089, 345]
[I]0: 94.56%, [886, 222, 970, 327]
[I]0: 94.12%, [1141, 145, 1262, 281]
[I]0: 93.96%, [487, 249, 571, 370]
[I]0: 93.94%, [331, 201, 430, 341]
[I]0: 93.27%, [186, 192, 302, 351]
[I]0: 62.17%, [607, 233, 692, 338]
root@1657ec5355e2:/data/pulsar2-run-helper#

  1. 具体工具文档如下:
  2. [pulsar2工具文档](https://pulsar2-docs.readthedocs.io/zh-cn/latest/user_guides_quick)
  3. ## 开发板运行
  4. 开发板镜像为1.27版本,采用本地编译
  5. 下载源码:

git clone https://github.com/AXERA-TECH/ax-samples.git

  1. 修改ax_yolov5s_steps.cc文件中:

修改classname标签
const char* CLASS_NAMES[] = {
"person", "hat"};
generate_proposals_yolov5函数指定classnum数量为2
for (uint32_t i = 0; i < io_info->nOutputSize; ++i)
{
auto& output = io_data->pOutputs[i];
auto& info = io_info->pOutputs[i];
auto ptr = (float*)output.pVirAddr;
int32_t stride = (1 << i) * 8;
detection::generate_proposals_yolov5(stride, ptr, PROB_THRESHOLD, proposals, input_w, input_h, ANCHORS, prob_threshold_u_sigmoid,2);
}

  1. 修改的原因是它默认为80,不然会报错下面信息:

root@maixbox:/home/ax-samples/build/install/ax650# ./ax_yolov5s -m yolov5s_hat.axmodel -i 000032.jpg

model file : yolov5s_hat.axmodel
image file : 000032.jpg
img_h, img_w : 640 640


WARN,Func(is_valid_file),NOT find file = '/etc/ax_syslog.conf'
ERROR,Func(
syslog_parma_cfg_get), NOT find = '/etc/ax_syslog.conf'
Engine creating handle is done.
Engine creating context is done.
Engine get io info is done.
Engine alloc io is done.
Engine push input is done.


Segmentation fault

  1. ![picture 9](https://img2023.cnblogs.com/blog/2915785/202311/2915785-20231116182454221-175286927.png)

cd ax-samples
mkdir build && cd build
cmake -DBSP_MSP_DIR=/soc/ -DAXERA_TARGET_CHIP=ax650 ..
make -j6
make install

  1. 编译完成后,生成的可执行示例存放在 `ax-samples/build/install/ax650/` 路径下:
  2. ```bash
  3. ax-samples/build$ tree install
  4. install
  5. └── ax650
  6. ├── ax_classification
  7. ├── ax_detr
  8. ├── ax_dinov2
  9. ├── ax_glpdepth
  10. ├── ax_hrnet
  11. ├── ax_imgproc
  12. ├── ax_pfld
  13. ├── ax_pp_humanseg
  14. ├── ax_pp_liteseg_stdc2_cityscapes
  15. ├── ax_pp_ocr_rec
  16. ├── ax_pp_person_attribute
  17. ├── ax_pp_vehicle_attribute
  18. ├── ax_ppyoloe
  19. ├── ax_ppyoloe_obj365
  20. ├── ax_realesrgan
  21. ├── ax_rtmdet
  22. ├── ax_scrfd
  23. ├── ax_segformer
  24. ├── ax_simcc_pose
  25. ├── ax_yolo_nas
  26. ├── ax_yolov5_face
  27. ├── ax_yolov5s
  28. ├── ax_yolov5s_seg
  29. ├── ax_yolov6
  30. ├── ax_yolov7
  31. ├── ax_yolov7_tiny_face
  32. ├── ax_yolov8
  33. ├── ax_yolov8_pose
  34. └── ax_yolox

讲axmodel模型放在可执行文件下和测试图片:

  1. root@maixbox:/home/ax-samples/build/install/ax650# ./ax_yolov5s -m yolov5s_hat.axmodel -i 000032.jpg
  2. --------------------------------------
  3. model file : yolov5s_hat.axmodel
  4. image file : 000032.jpg
  5. img_h, img_w : 640 640
  6. --------------------------------------
  7. WARN,Func(__is_valid_file),NOT find file = '/etc/ax_syslog.conf'
  8. ERROR,Func(__syslog_parma_cfg_get), NOT find = '/etc/ax_syslog.conf'
  9. Engine creating handle is done.
  10. Engine creating context is done.
  11. Engine get io info is done.
  12. Engine alloc io is done.
  13. Engine push input is done.
  14. --------------------------------------
  15. post process cost time:0.42 ms
  16. --------------------------------------
  17. Repeat 1 times, avg time 6.15 ms, max_time 6.15 ms, min_time 6.15 ms
  18. --------------------------------------
  19. detection num: 7
  20. 0:95%, [ 981,221, 1080,342], person
  21. 0:95%, [ 332,201,431,341], person
  22. 0:95%, [ 886,222,970,327], person
  23. 0:94%, [1141,140, 1262,290], person
  24. 0:94%, [ 187,197,300,347], person
  25. 0:94%, [ 487,252,571,373], person
  26. 0:91%, [ 605,232,689,337], person
  27. --------------------------------------

picture 10

感谢

感谢o0圏圏蟲0o,无事闲来梦醒时分N/A秋水等大佬的帮助

此帖出自Linux开发论坛
点赞 关注

回复
举报
您需要登录后才可以回帖 登录 | 注册

查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
推荐帖子
[吐血推荐]^_^单片机多媒体教程-下载地址

http://wstatic.xunlei.com/web/download.htm?cid=446712C427207D83DBBD6E963CF09CC55BBF9BA2迅雷上的,速度很快.分享一下,没人反 ...

ZT:电子毕业生如何规划你的人生

一、 怎样规划你的毕业后的人生     我今年39岁了, 25岁研究生毕业,工作14年,回头看看,应该说走了不少的弯路,有一些 ...

实现第二步: 自己DIY一个廉价的C8051编程器并成功读写湿度计开发板

昨天用洞洞板按照我前面帖子提供的图纸焊接出一个并口C8051编程器。 今天一早插到PC机上,运行编程器文件(前面帖子附件可下 ...

【玩转C2000 LaunchPad】在FLASH里运行

【C2000 LaunchPad】在FLASH里运行 在FLASH里运行程序,只是将程序烧写到FLASH中,与在RAM里运行没有本质的区别。但是在FLA ...

Helper2416-13——裸机第五弹——YL-boot——裸奔者的福音

YL-boot——裸奔者的福音 参与Helper2416开发板助学计划心得 闭关几天,终于初步完成了这YL-boot了。没有J-TAG不能单步调试还 ...

安泰测试—泰克AFG3021任意信号发生器维修经验分享

本帖最后由 agitek安泰维修 于 2020-4-23 19:09 编辑 之前给大家分享示波器相关的维修方法和维修实例比较多,今天给大家来分 ...

ALTIUM DESIGNER几乎所有焊盘的STACK MODE都变成了FULL STACK是怎么回事?

以前用的好好的,不知道从哪天开始,PCB库里的多层焊盘全部变成FULL STACK了,结果就是顶层有焊盘,底层就是一个孔。 在网上 ...

[国产FPGA高云GW1N 系列开发板测评]——(2)点灯和流水灯

本帖最后由 chg0823 于 2021-12-16 00:39 编辑 收到高云FPGA GW1N-4B开发板,打开一看感到很吃惊,竟然接了那么多LED,可 ...

【DigiKey“智造万物,快乐不停”创意大赛】全胸腔体外振荡排痰系统_03

本帖最后由 Jack刘工 于 2023-12-26 14:58 编辑 【DigiKey“智造万物,快乐不停”创意大赛】 全胸腔体外振荡排 ...

《机器学习算法与实现》6、神经网络

一、多层神经网络 基于生物神经元模型可得到多层感知机(MLP)的基本结构,最典型的MLP包括三层:输入层、隐藏层和输出层。 ...

关闭
站长推荐上一条 1/10 下一条
有奖直播报名| TI 面向楼宇和工厂自动化行业的毫米波雷达解决方案
【内容简介】TI 60GHz IWRL6432和 IWRL1432毫米波雷达传感器如何帮助解决楼宇和工厂自动化应用中的感应难题
【直播时间】5月28日(周三)上午10:00
【直播礼品】小米双肩包、contigo水杯、胶囊伞、安克充电器

查看 »

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

 
机器人开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网 3

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表