跳到主要内容

YOLOv8-seg 目标分割

  • 进入 Radxa Model-zoo YOLOv8_seg 目录

    cd Radxa-Model-Zoo/sample/YOLOv8_seg
  • 下载模型,可选 F32/F16/INT8 量化模型

    # F32
    wget https://github.com/radxa-edge/TPU-Edge-AI/releases/download/model-zoo/yolov8s_fp32_1b.bmodel

    # F16
    wget https://github.com/radxa-edge/TPU-Edge-AI/releases/download/model-zoo/yolov8s_fp16_1b.bmodel

    # INT8
    wget https://github.com/radxa-edge/TPU-Edge-AI/releases/download/model-zoo/yolov8s_int8_1b.bmodel
  • 下载测试图片到数据文件夹

    mkdir images && cd images
    wget https://github.com/radxa-edge/TPU-Edge-AI/releases/download/model-zoo/dog_bike_car.jpg
  • 创建虚拟环境

    必须创建虚拟环境,否则可能会影响其他应用的正常运行, 虚拟环境使用请参考这里

    python3 -m virtualenv .venv
    source .venv/bin/activate
  • 安装 python 依赖包

    pip3 install --upgrade pip
    pip3 install numpy pycocotools
    pip3 install https://github.com/radxa-edge/TPU-Edge-AI/releases/download/v0.1.0/sophon_arm-3.7.0-py3-none-any.whl
  • 运行 python 示例

    python 目录下提供了一系列Python例程,具体情况如下:

    序号Python例程说明
    1yolov8_opencv.py使用OpenCV解码、OpenCV前处理、SAIL推理
    2yolov8_bmcv.py使用SAIL解码、BMCV前处理、SAIL推理
    • 运行 yolov8_opencv.py

      export LD_LIBRARY_PATH=/opt/sophon/libsophon-current/lib:$LD_LIBRARY_PATH
      export PYTHONPATH=$PYTHONPATH:/opt/sophon/sophon-opencv-latest/opencv-python/
      python3 python/yolov8_opencv.py --input ./images --bmodel ./yolov8s_int8_1b.bmodel

      参数说明

      yolov8_opencv.py [--input IMG_PATH] [--bmodel BMODEL]

      --input: 推理图片路径,可输入整个图片文件夹的路径或视频路径

      --bmodel: 用于推理的 bmodel 路径

      (.venv) linaro@bm1684:/data/ssd/docs_check/Radxa-Model-Zoo/sample/YOLOv8_seg$ python3 python/yolov8_opencv.py --input ./images --bmodel ./yolov8s_int8_1b.bmodel
      [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 [./yolov8s_int8_1b.bmodel]. Thanks for your patience...
      [BMRT][load_bmodel:1023] INFO:pre net num: 0, load net num: 1
      INFO:root:load ./yolov8s_int8_1b.bmodel success!
      INFO:root:1, img_file: ./images/dog_bike_car.jpg
      sampleFactor=6, cinfo->num_components=3 (1x2, 1x1, 1x1)
      Open /dev/jpu successfully, device index = 0, jpu fd = 23, vpp fd = 24
      INFO:root:result saved in ./results/yolov8s_int8_1b.bmodel_images_opencv_python_result.json
      INFO:root:------------------ Predict Time Info ----------------------
      INFO:root:decode_time(ms): 16.52
      INFO:root:preprocess_time(ms): 30.85
      INFO:root:inference_time(ms): 16.11
      INFO:root:postprocess_time(ms): 71.09
      all done.

      运行结果会保存在 ./results/yolov8s_int8_1b.bmodel_images_opencv_python_result.json

      图片结果保存在 ./result/images

      yolov8_seg_1.webp

    • 运行 yolov8_bmcv.py

      export LD_LIBRARY_PATH=/opt/sophon/libsophon-current/lib:$LD_LIBRARY_PATH
      export PYTHONPATH=$PYTHONPATH:/opt/sophon/sophon-opencv-latest/opencv-python/
      python3 python/yolov8_bmcv.py --input ./images --bmodel ./yolov8s_int8_1b.bmodel

      参数说明

      yolov8_bmcv.py [--input IMG_PATH] [--bmodel BMODEL]

      --input: 推理图片路径,可输入整个图片文件夹的路径或视频路径

      --bmodel: 用于推理的 bmodel 路径

      (.venv) linaro@bm1684:/data/ssd/docs_check/Radxa-Model-Zoo/sample/YOLOv8_seg$ python3 python/yolov8_bmcv.py  --input ./images --bmodel ./yolov8s_int8_1b.bmodel
      [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 [./yolov8s_int8_1b.bmodel]. Thanks for your patience...
      [BMRT][load_bmodel:1023] INFO:pre net num: 0, load net num: 1
      INFO:root:1, img_file: ./images/dog_bike_car.jpg
      sampleFactor=6, cinfo->num_components=3 (1x2, 1x1, 1x1)
      Open /dev/jpu successfully, device index = 0, jpu fd = 42, vpp fd = 43
      INFO:root:result saved in ./results/yolov8s_int8_1b.bmodel_images_bmcv_python_result.json
      INFO:root:------------------ Predict Time Info ----------------------
      INFO:root:decode_time(ms): 15.48
      INFO:root:preprocess_time(ms): 2.65
      INFO:root:inference_time(ms): 13.13
      INFO:root:postprocess_time(ms): 66.66
      all done.

      运行结果会保存在 ./results/yolov8s_int8_1b.bmodel_images_bmcv_python_result.json

      图片结果保存在 ./result/images yolov8_seg_2.webp

FAQ

更多有关模型转换,模型量化细节, 模型精度测试,请参考

模型转换Radxa Model-Zoo YOLOv8-seg