sophgo / sophon-demo

Other
233 stars 51 forks source link

导出yolov8n-pose模型精度问题 #31

Open jiangzhiwei2018 opened 7 months ago

jiangzhiwei2018 commented 7 months ago

使用如下方法导出yolov8n-pose模型,该onnx使用NVIDIA显卡推理没有问题

导出bmodel后在平台上能够成功加载,但检测不到,完整的视频只能够检测到极少部分,精度差异比较大。

这是根据 YOLOv8_det的导出脚本修改的gen_fp32bmodel_mlir.sh

#!/bin/bash
model_dir=$(dirname $(readlink -f "$0"))

if [ ! $1 ]; then
    target=bm1684
    target_dir=BM1684
else
    target=${1,,}
    target_dir=${target^^}
fi

if [ ! $2 ]; then
    model_name=yolov8s
else
    model_name=${2}
fi

outdir=../models/$target_dir
rm -rf /workspace/transforms/YOLOv8-pose/scripts/*.onnx /workspace/transforms/YOLOv8-pose/scripts/${model_name}*
function gen_mlir()
{   
    model_transform.py \
        --model_name ${model_name}_1output \
        --model_def ../models/onnx/${model_name}.onnx \
        --input_shapes [[$1,3,384,640]] \
        --mean 0.0,0.0,0.0 \
        --scale 0.0039216,0.0039216,0.0039216 \
        --keep_aspect_ratio \
        --pixel_format rgb  \
        --mlir ${model_name}_$1b.mlir
}

function gen_fp32bmodel()
{
    model_deploy.py \
        --mlir ${model_name}_$1b.mlir \
        --quantize F32 \
        --chip $target \
        --model ${model_name}_fp32_$1b.bmodel

    mv ${model_name}_fp32_$1b.bmodel $outdir/
}

pushd $model_dir
if [ ! -d $outdir ]; then
    mkdir -p $outdir
fi
# batch_size=1
gen_mlir 1
gen_fp32bmodel 1

popd

运行命令:./scripts/gen_fp32bmodel_mlir.sh bm1684 yolov8n-pose-4Classes-384x640

tpu-mlir 版本

tpu-mlir_v1.2.8-g32d7b3ec-20230802

此外使用该方法导出的yolov8目标检测模型能够正常工作,pose和detection模型输入时的前处理相同,pose模型的输出会多n*2列数据(n为特征点的数量),其余相同。 bmode和onnx后处理使用的同一套逻辑代码。

sophon-leevi commented 7 months ago

精度问题,请先确认一下模型是否有问题,mlir加个test_input,具体你可以参考一下https://github.com/sophgo/sophon-demo/blob/release/sample/YOLOv5/scripts/gen_int8bmodel_mlir.sh