Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] RTMDet-Ins coreml export failed. #2870

Open
3 tasks done
faketifosi opened this issue Jan 13, 2025 · 0 comments
Open
3 tasks done

[Bug] RTMDet-Ins coreml export failed. #2870

faketifosi opened this issue Jan 13, 2025 · 0 comments

Comments

@faketifosi
Copy link

faketifosi commented Jan 13, 2025

Checklist

  • I have searched related issues but cannot get the expected help.
  • 2. I have read the FAQ documentation but cannot get the expected help.
  • 3. The bug has not been fixed in the latest version.

Describe the bug

I'm using mmdeploy to convert pretrained RTMDet-Ins-tiny model to ONNX and TorchScript, and both conversions are successful. However, when I convert the model to CoreML, the output bboxes and scores are correct, but the mask output's position and size are incorrect.

output_pytorch
output_pytorch

output_onnxruntime
output_onnxruntime

output_coreml
output_coreml

Reproduction

  1. Add a configuration base_instance-seg_coreml.py for deployment.

    _base_ = ['./base_torchscript.py', '../../_base_/backends/coreml.py']
    
    ir_config = dict(output_names=['dets', 'labels', 'masks'])
    codebase_config = dict(post_processing=dict(export_postprocess_mask=False))
    
    backend_config = dict(model_inputs=[
        dict(
            input_shapes=dict(
                input=dict(
                    min_shape=[1, 3, 640, 640],
                    max_shape=[1, 3, 640, 640],
                    default_shape=[1, 3, 640, 640])))
    ])
  2. Download prebuilt arm64 libtorch via link

  3. Install the following packages via pip
    coremltools==8.1
    torch==2.2.0
    torchvision==0.17.0
    numpy==1.26.4
    PyYAML==6.0.1
    openmim==0.3.9
    wheel==0.43.0
    coremltools==8.1
    scikit-learn==1.1.2
    ipyplot==1.1.2
    opencv-python

  4. Install mmengine
    mim install mmengine
    mim install "mmcv>=2.0.0rc4, <2.2.0"

  5. I followed the instructions in this notebook: https://github.com/gustavofuhr/ios_object_detection/blob/main/rtmdet_mmdetection_to_coreml/export_mmdetection_coreml.ipynb to build and install mmdeploy v1.3.1 (commit hash: bc75c9d) and mmdet v3.3.0 (commit hash: 44ebd17b145c2372c4b700bfb9cb20dbd28ab64a).

  6. Run mmdeploy
    python mmdeploy/tools/deploy.py mmdeploy/configs/mmdet/_base_/base_instance-seg_coreml.py mmdetection/configs/rtmdet/rtmdet-ins_tiny_8xb32-300e_coco.py rtmdet-ins_tiny_8xb32-300e_coco_20221130_151727-ec670f7e.pth mmdetection/demo/demo.jpg --work-dir rtmdet-ins-tiny --device cpu --dump-info

Environment

$ python third_party/mmdeploy/tools/check_env.py 
01/13 11:12:24 - mmengine - INFO - 

01/13 11:12:24 - mmengine - INFO - **********Environmental information**********
01/13 11:12:26 - mmengine - INFO - sys.platform: darwin
01/13 11:12:26 - mmengine - INFO - Python: 3.9.6 (default, Aug  9 2024, 14:24:13) [Clang 16.0.0 (clang-1600.0.26.3)]
01/13 11:12:26 - mmengine - INFO - CUDA available: False
01/13 11:12:26 - mmengine - INFO - MUSA available: False
01/13 11:12:26 - mmengine - INFO - numpy_random_seed: 2147483648
01/13 11:12:26 - mmengine - INFO - GCC: Apple clang version 16.0.0 (clang-1600.0.26.3)
01/13 11:12:26 - mmengine - INFO - PyTorch: 2.2.0
01/13 11:12:26 - mmengine - INFO - PyTorch compiling details: PyTorch built with:
  - GCC 4.2
  - C++ Version: 201703
  - clang 14.0.3
  - OpenMP 201811
  - LAPACK is enabled (usually provided by MKL)
  - NNPACK is enabled
  - CPU capability usage: NO AVX
  - Build settings: BLAS_INFO=accelerate, BUILD_TYPE=Release, CXX_COMPILER=/Applications/Xcode_14.3.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++, CXX_FLAGS= -fvisibility-inlines-hidden -DUSE_PTHREADPOOL -DNDEBUG -DUSE_KINETO -DLIBKINETO_NOCUPTI -DLIBKINETO_NOROCTRACER -DUSE_PYTORCH_QNNPACK -DUSE_XNNPACK -DUSE_PYTORCH_METAL_EXPORT -DSYMBOLICATE_MOBILE_DEBUG_HANDLE -DUSE_COREML_DELEGATE -O2 -fPIC -Wall -Wextra -Werror=return-type -Werror=non-virtual-dtor -Werror=braced-scalar-init -Werror=range-loop-construct -Werror=bool-operation -Wnarrowing -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wno-unused-parameter -Wno-unused-function -Wno-unused-result -Wno-strict-overflow -Wno-strict-aliasing -Wvla-extension -Wsuggest-override -Wnewline-eof -Winconsistent-missing-override -Winconsistent-missing-destructor-override -Wno-pass-failed -Wno-error=pedantic -Wno-error=old-style-cast -Wno-error=inconsistent-missing-override -Wno-error=inconsistent-missing-destructor-override -Wconstant-conversion -Wno-invalid-partial-specialization -Wno-missing-braces -Qunused-arguments -fcolor-diagnostics -faligned-new -Wno-unused-but-set-variable -fno-math-errno -fno-trapping-math -Werror=format -DUSE_MPS -Wno-unused-private-field -Wno-missing-braces, LAPACK_INFO=accelerate, TORCH_VERSION=2.2.0, USE_CUDA=OFF, USE_CUDNN=OFF, USE_EIGEN_FOR_BLAS=ON, USE_EXCEPTION_PTR=1, USE_GFLAGS=OFF, USE_GLOG=OFF, USE_MKL=OFF, USE_MKLDNN=OFF, USE_MPI=OFF, USE_NCCL=OFF, USE_NNPACK=ON, USE_OPENMP=ON, USE_ROCM=OFF, USE_ROCM_KERNEL_ASSERT=OFF, 

01/13 11:12:26 - mmengine - INFO - TorchVision: 0.17.0
01/13 11:12:26 - mmengine - INFO - OpenCV: 4.10.0
01/13 11:12:26 - mmengine - INFO - MMEngine: 0.10.5
01/13 11:12:26 - mmengine - INFO - MMCV: 2.1.0
01/13 11:12:26 - mmengine - INFO - MMCV Compiler: clang 16.0.0
01/13 11:12:26 - mmengine - INFO - MMCV CUDA Compiler: not available
01/13 11:12:26 - mmengine - INFO - MMDeploy: 1.3.1+1e889a6
01/13 11:12:26 - mmengine - INFO - 

01/13 11:12:26 - mmengine - INFO - **********Backend information**********
01/13 11:12:26 - mmengine - INFO - tensorrt:	None
01/13 11:12:26 - mmengine - INFO - ONNXRuntime:	1.19.2
01/13 11:12:26 - mmengine - INFO - ONNXRuntime-gpu:	None
01/13 11:12:26 - mmengine - INFO - ONNXRuntime custom ops:	NotAvailable
01/13 11:12:26 - mmengine - INFO - pplnn:	None
01/13 11:12:26 - mmengine - INFO - ncnn:	None
01/13 11:12:26 - mmengine - INFO - snpe:	None
01/13 11:12:26 - mmengine - INFO - openvino:	None
01/13 11:12:26 - mmengine - INFO - torchscript:	2.2.0
01/13 11:12:26 - mmengine - INFO - torchscript custom ops:	Available
01/13 11:12:26 - mmengine - INFO - rknn-toolkit:	None
01/13 11:12:26 - mmengine - INFO - rknn-toolkit2:	None
01/13 11:12:26 - mmengine - INFO - ascend:	None
01/13 11:12:26 - mmengine - INFO - coreml:	8.1
01/13 11:12:26 - mmengine - INFO - tvm:	None
01/13 11:12:26 - mmengine - INFO - vacc:	None
01/13 11:12:26 - mmengine - INFO - 

01/13 11:12:26 - mmengine - INFO - **********Codebase information**********
01/13 11:12:26 - mmengine - INFO - mmdet:	3.3.0
01/13 11:12:26 - mmengine - INFO - mmseg:	None
01/13 11:12:26 - mmengine - INFO - mmpretrain:	None
01/13 11:12:26 - mmengine - INFO - mmocr:	None
01/13 11:12:26 - mmengine - INFO - mmagic:	None
01/13 11:12:26 - mmengine - INFO - mmdet3d:	None
01/13 11:12:26 - mmengine - INFO - mmpose:	None
01/13 11:12:26 - mmengine - INFO - mmrotate:	None
01/13 11:12:26 - mmengine - INFO - mmaction:	None
01/13 11:12:26 - mmengine - INFO - mmrazor:	None
01/13 11:12:26 - mmengine - INFO - mmyolo:	None

Error traceback

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant