专栏算法工具链j6m 多batch 输入ptq 方法确认

j6m 多batch 输入ptq 方法确认

已解决
默认232322024-11-18
141
11

 

 

1. 芯片型号:j6

2. 板卡类型:地平线Matrix-6M

3. 天工开物开发包 OpenExplorer 版本:3.0.17

4. 问题定位:模型转换、板端部署等

5. 问题具体描述:

第一步 检查模型 
onnx_model="./bs4.onnx"
march="nash-m"


hb_compile --model ${onnx_model} \
  --input-shape images 4x3x768x1280 \
  --march ${march}

 

第二步  每一个图片进行预处理, 并且将每4个关联图片作为一组存储为npy   

python3 ../../data_preprocess.py \
  --src_dir ./calibration_data \
  --dst_dir ./calibration_data_bgr_j6 \
  --pic_ext .bgr \
  --read_mode opencv \
  --saved_data_type float32 \
  --cal_img_num 120

 

第三步  量化

config_file="./bs4.yaml"


hb_compile --config ${config_file}

 

请问以上操作是否正确 ? 

 

由于oe sdk-3.0.17 里面没有多batch 量化sample,外加 hb_compile  没有说明读取标定数据的方式。
算法工具链
征程6
+1
评论5
0/1000
  • Huanghui
    Lv.5

    你好,在做这个之前你要确定一下,PTQ中你期望的输入是NV12还是featuremap,如果NV12目前还不支持多BATCH。

    另外,j6工具链目前已经升级到了3.0.22,你先升级一下吧,查问题也方便,工具链使用说明中有NV12多BATCH的说明。

    2024-11-18
    0
    0
  • DR_KAN
    Lv.4
    你好,根据目前已有信息来看,这样操作没有问题,对于原始onnx的batch就是4的情况,确实要把4张校准数据拼在一起,这个是对的。
    另外,可以再注意以下几点:
    1、参考手册中《训练后量化(PTQ)常见问题》的“如何编译得到多 batch 模型?”,确保其他操作正确
    2、参考手册中《模型量化编译》章节的input_batch、separate_batch等相关参数说明,确保使用了正确的参数配置,尤其是,input_batch参数仅在 input_shape 第一维为1的时候可以使用
    3、另外,如果input_type_rt配置了nv12,那么目前这种情况不支持多batch
    2024-11-18
    0
    1
    • 默认23232回复DR_KAN:

      thanks

      2024-11-18
      0
  • 默认23232
    Lv.2
    你好,我目前工具链sdk3.0.17 版本,我目前没法从地平线对接人员拿到最新版本。
    输入是featuremap,我的yaml文件input_parameters如下

    input_parameters:

    # Specify the input node name of the original floating-point model,

    # consistent with its name in the model, not specified will be obtained from the model

    input_name: ""

    # Specify the input data of the on-board model, with range: nv12/rgb/bgr/yuv444/gray/featuremap

    # The number/order specified need to be the same as in input_name

    input_type_rt: 'featuremap'

    # Specify the input data type of the original floating-point model, with range: rgb/bgr/gray/yuv444/featuremap

    # The number/order specified need to be the same as in input_name

    input_type_train: 'bgr'

    # Specify the input data layout of the original floating-point model, with range: NHWC/NCHW

    # The number/order specified need to be the same as in input_name

    input_layout_train: 'NCHW'

    # Specify the input shape of the original floating-point model, e.g. 1x3x224x224;1x2x224x224

    input_shape: '4x3x768x1280'

    2024-11-18
    0
    1
    • DR_KAN回复默认23232:

      featuremap没法转换成bgr,建议rt和train都配置成bgr

      2024-11-18
      0
  • Huanghui
    Lv.5

    rt_type是featuremap,train_type只能也是featuremap!

    2024-11-18
    0
    4
    • 默认23232回复Huanghui:
      thks,都配成featuremap,是可以进行ptq.
      如果都配成bgr, 会报错

      [==================================================]100%

      HBDK hbm perf SUCCESS

      ...

      2024-11-18 11:14:26,901 INFO check params start

      2024-11-18 11:14:27,856 INFO check params end

      2024-11-18 11:14:27,869 INFO SV_SOD_20241101_bs4_j6_optimized_float_model inference...

      2024-11-18 11:14:28,580 INFO SV_SOD_20241101_bs4_j6_quantized_model inference...

      2024-11-18 11:14:28,601 ERROR launch runner failed. reason 0-th input dim0 shape mismatch: expected 4 got 1


      2024-11-18
      0
    • DR_KAN回复默认23232:

      好的,看来如果是bgr,工具链会希望你拆开成4个batch=1的输入,那就只能用featuremap了

      2024-11-18
      0
    • Huanghui回复默认23232:
      好的,不过还是要说一下,尽量升级到3.0.22,新版本在老版本基础上进行了一些升级和功能删减。1)如果测试过程遇到问题,还是会希望你在新版本基础上验证;2)如果确实是工具链的bug研发同学修复问题也是基于新的版本进行修复;3)新版本中已经删减的内容,如果还在旧的版本进行使用没多少意义,迟早是要升级的,不如趁早。4)3.0.22手册中给出了batch>的解决方式:现在featuremap下进行PTQ生成bc,然后将BT处理成8个batch=1的输入(4组Y+UV),这样才利于最终部署!
      2024-11-18
      1
    • 默认23232回复Huanghui:

      好的,感谢两位,我这边会想办法拿到最新工具链再试一试@DR_KAN @Huanghui

      2024-11-19
      0
  • Huanghui
    Lv.5

    客户您好,鉴于长时间未收到你的答复,我们暂将该问题做关闭处理,如您仍有相同问题,请在新的帖子中重新发起提问,祝您工作愉快!

    2024-12-02
    0
    0