open-mmlab / mmdeploy

OpenMMLab Model Deployment Framework
https://mmdeploy.readthedocs.io/en/latest/
Apache License 2.0
2.79k stars 637 forks source link

[Bug] 使用rtmpose训练的人体关键点检测模型在多人的情况下结果存在问题 #2459

Closed vicnoah closed 1 year ago

vicnoah commented 1 year ago

Checklist

Describe the bug

使用mmdeploy进行mmpose预测时结果不正确 训练使用的是coco_2017数据集 配置文件rtmpose-m_8xb256-420e_coco-256x192.py

代码

from mmdeploy_runtime import PoseDetector
import cv2
import numpy as np

detector = PoseDetector(model_path='mmdeploy_models/mmpose/people',
                    device_name='cpu', device_id=0)

# 轨标检测
class MMAI:
    # 初始化方法,设置阈值为0.5
    def __init__(self, thresh = 0.5):
        self.thresh = thresh

    # reco方法,输入图片路径,返回检测到的目标框列表
    def reco(self, path):
        try:

            # 读取图片
            img = cv2.imread(path)
            # 进行目标检测
            result = detector(img)

            _, point_num, _ = result.shape
            points = result[:, :, :2].reshape(point_num, 2)
            for [x, y] in points.astype(int):
                cv2.circle(img, (x, y), 1, (0, 255, 0), 2)

            cv2.imwrite('output_pose.png', img)

            print(result)
            return

        except Exception as e:
            print(e)
            return None

ai = MMAI()

ai.reco("demo.jpg")

单人原图 image 检测结果 image

多人原图 image 检测结果 image

Reproduction

class MMAI:
    # 初始化方法,设置阈值为0.5
    def __init__(self, thresh = 0.5):
        self.thresh = thresh

    # reco方法,输入图片路径,返回检测到的目标框列表
    def reco(self, path):
        try:

            # 读取图片
            img = cv2.imread(path)
            # 进行目标检测
            result = detector(img)

            _, point_num, _ = result.shape
            points = result[:, :, :2].reshape(point_num, 2)
            for [x, y] in points.astype(int):
                cv2.circle(img, (x, y), 1, (0, 255, 0), 2)

            cv2.imwrite('output_pose.png', img)

            print(result)
            return

        except Exception as e:
            print(e)
            return None

ai = MMAI()

ai.reco("demo.jpg")

Environment

09/25 03:45:51 - mmengine - INFO - 

09/25 03:45:51 - mmengine - INFO - **********Environmental information**********
09/25 03:45:52 - mmengine - INFO - sys.platform: linux
09/25 03:45:52 - mmengine - INFO - Python: 3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0]
09/25 03:45:52 - mmengine - INFO - CUDA available: False
09/25 03:45:52 - mmengine - INFO - numpy_random_seed: 2147483648
09/25 03:45:52 - mmengine - INFO - GCC: x86_64-linux-gnu-gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
09/25 03:45:52 - mmengine - INFO - PyTorch: 2.0.1+cu118
09/25 03:45:52 - mmengine - INFO - PyTorch compiling details: PyTorch built with:
  - GCC 9.3
  - C++ Version: 201703
  - Intel(R) oneAPI Math Kernel Library Version 2022.2-Product Build 20220804 for Intel(R) 64 architecture applications
  - Intel(R) MKL-DNN v2.7.3 (Git Hash 6dbeffbae1f23cbbeae17adb7b5b13f1f37c080e)
  - OpenMP 201511 (a.k.a. OpenMP 4.5)
  - LAPACK is enabled (usually provided by MKL)
  - NNPACK is enabled
  - CPU capability usage: AVX2
  - Build settings: BLAS_INFO=mkl, BUILD_TYPE=Release, CUDA_VERSION=11.8, CUDNN_VERSION=8.7.0, CXX_COMPILER=/opt/rh/devtoolset-9/root/usr/bin/c++, CXX_FLAGS= -D_GLIBCXX_USE_CXX11_ABI=0 -fabi-version=11 -Wno-deprecated -fvisibility-inlines-hidden -DUSE_PTHREADPOOL -DNDEBUG -DUSE_KINETO -DLIBKINETO_NOROCTRACER -DUSE_FBGEMM -DUSE_QNNPACK -DUSE_PYTORCH_QNNPACK -DUSE_XNNPACK -DSYMBOLICATE_MOBILE_DEBUG_HANDLE -O2 -fPIC -Wall -Wextra -Werror=return-type -Werror=non-virtual-dtor -Werror=bool-operation -Wnarrowing -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wunused-local-typedefs -Wno-unused-parameter -Wno-unused-function -Wno-unused-result -Wno-strict-overflow -Wno-strict-aliasing -Wno-error=deprecated-declarations -Wno-stringop-overflow -Wno-psabi -Wno-error=pedantic -Wno-error=redundant-decls -Wno-error=old-style-cast -fdiagnostics-color=always -faligned-new -Wno-unused-but-set-variable -Wno-maybe-uninitialized -fno-math-errno -fno-trapping-math -Werror=format -Werror=cast-function-type -Wno-stringop-overflow, LAPACK_INFO=mkl, PERF_WITH_AVX=1, PERF_WITH_AVX2=1, PERF_WITH_AVX512=1, TORCH_DISABLE_GPU_ASSERTS=ON, TORCH_VERSION=2.0.1, USE_CUDA=ON, USE_CUDNN=ON, USE_EXCEPTION_PTR=1, USE_GFLAGS=OFF, USE_GLOG=OFF, USE_MKL=ON, USE_MKLDNN=ON, USE_MPI=OFF, USE_NCCL=1, USE_NNPACK=ON, USE_OPENMP=ON, USE_ROCM=OFF, 

09/25 03:45:52 - mmengine - INFO - TorchVision: 0.15.2+cu118
09/25 03:45:52 - mmengine - INFO - OpenCV: 4.8.0
09/25 03:45:52 - mmengine - INFO - MMEngine: 0.8.4
09/25 03:45:52 - mmengine - INFO - MMCV: 2.0.1
09/25 03:45:52 - mmengine - INFO - MMCV Compiler: GCC 9.3
09/25 03:45:52 - mmengine - INFO - MMCV CUDA Compiler: 11.8
09/25 03:45:52 - mmengine - INFO - MMDeploy: 1.2.0+1132e82
09/25 03:45:52 - mmengine - INFO - 

09/25 03:45:52 - mmengine - INFO - **********Backend information**********
09/25 03:45:52 - mmengine - INFO - tensorrt:    None
09/25 03:45:52 - mmengine - INFO - ONNXRuntime: 1.16.0
09/25 03:45:52 - mmengine - INFO - ONNXRuntime-gpu: None
09/25 03:45:52 - mmengine - INFO - ONNXRuntime custom ops:  Available
09/25 03:45:52 - mmengine - INFO - pplnn:   None
09/25 03:45:52 - mmengine - INFO - ncnn:    None
09/25 03:45:52 - mmengine - INFO - snpe:    None
09/25 03:45:52 - mmengine - INFO - openvino:    None
09/25 03:45:52 - mmengine - INFO - torchscript: 2.0.1+cu118
09/25 03:45:52 - mmengine - INFO - torchscript custom ops:  NotAvailable
09/25 03:45:52 - mmengine - INFO - rknn-toolkit:    None
09/25 03:45:52 - mmengine - INFO - rknn-toolkit2:   None
09/25 03:45:52 - mmengine - INFO - ascend:  None
09/25 03:45:52 - mmengine - INFO - coreml:  None
09/25 03:45:52 - mmengine - INFO - tvm: None
09/25 03:45:52 - mmengine - INFO - vacc:    None
09/25 03:45:52 - mmengine - INFO - 

09/25 03:45:52 - mmengine - INFO - **********Codebase information**********
09/25 03:45:52 - mmengine - INFO - mmdet:   3.1.0
09/25 03:45:52 - mmengine - INFO - mmseg:   None
09/25 03:45:52 - mmengine - INFO - mmpretrain:  None
09/25 03:45:52 - mmengine - INFO - mmocr:   None
09/25 03:45:52 - mmengine - INFO - mmagic:  None
09/25 03:45:52 - mmengine - INFO - mmdet3d: None
09/25 03:45:52 - mmengine - INFO - mmpose:  1.1.0
09/25 03:45:52 - mmengine - INFO - mmrotate:    None
09/25 03:45:52 - mmengine - INFO - mmaction:    None
09/25 03:45:52 - mmengine - INFO - mmrazor: None
09/25 03:45:52 - mmengine - INFO - mmyolo:  None

Error traceback

No response

irexyc commented 1 year ago

rtmpose 的输入是单人的图片。你如果想做多人的关键点检测,你需要在pose前面加一个检测模型。你可以参考 https://github.com/open-mmlab/mmdeploy/blob/main/demo/python/det_pose.py

vicnoah commented 1 year ago

rtmpose 的输入是单人的图片。你如果想做多人的关键点检测,你需要在pose前面加一个检测模型。你可以参考 https://github.com/open-mmlab/mmdeploy/blob/main/demo/python/det_pose.py

那检测模型需要重新训练吗?我只训练了一个关键点检测模型啊?

irexyc commented 1 year ago

现成的人体检测模型不满足你的需求(比如速度,精度)的话,就需要重新训练了。

vicnoah commented 1 year ago

现成的人体检测模型不满足你的需求(比如速度,精度)的话,就需要重新训练了。

好的谢谢