open-mmlab / mmsegmentation

OpenMMLab Semantic Segmentation Toolbox and Benchmark.
https://mmsegmentation.readthedocs.io/en/main/
Apache License 2.0
8.3k stars 2.62k forks source link

When I use mmseg and mmpose to predict images at the same time, the later model has overridden the former model #3656

Open AdamSuperTramp opened 6 months ago

AdamSuperTramp commented 6 months ago

Bug: Traceback (most recent call last): File "D:/Desktop/脚本/Adam-2训练&结果/加载3个模型/mmpose_predict_img.py", line 48, in result = inference_model(model, img_bgr) File "d:\desktop\science\model\mmsegmentation-main\mmseg\apis\inference.py", line 112, in inference_model data, is_batch = _preprare_data(img, model) File "d:\desktop\science\model\mmsegmentation-main\mmseg\apis\utils.py", line 29, in _preprare_data pipeline = Compose(cfg.test_pipeline) File "C:\Users\Adam\anaconda3\envs\mmlab\lib\site-packages\mmengine\dataset\base_dataset.py", line 38, in init transform = TRANSFORMS.build(transform) File "C:\Users\Adam\anaconda3\envs\mmlab\lib\site-packages\mmengine\registry\registry.py", line 570, in build return self.build_func(cfg, *args, **kwargs, registry=self) File "C:\Users\Adam\anaconda3\envs\mmlab\lib\site-packages\mmengine\registry\build_functions.py", line 100, in build_from_cfg raise KeyError( KeyError: 'PackSegInputs is not in the mmdet::transform registry. Please check whether the value of PackSegInputs is correct or it was registered as expected. More details can be found at https://mmengine.readthedocs.io/en/latest/advanced_tutorials/config.html#import-the-custom-module'

The following lines are my code to predict images, including segment by Knet and estimator poses by RTMpose:

# KNet
model = init_model(
    r"D:\Desktop\Unicorn\4.26\AdamDataset_KNet_20240426_2113.py",
    r"D:\Desktop\Unicorn\4.26\best_mIoU_iter_15000.pth",
    device=device
)

#  RTMPose
pose_estimator = init_pose_estimator(
    r"D:\Desktop\Science\Model\mmpose-main\work_dirs\rtmpose-s-tang2\20240429_130446\rtmpose-s-tang2.py",
    r"D:\Desktop\Science\Model\mmpose-main\work_dirs\rtmpose-s-tang2\20240429_130446\best_PCK_epoch_150.pth",
    device=device,
    cfg_options={'model': {'test_cfg': {'output_heatmaps': True}}}
)

# RTMDet
detector = init_detector(
    r"D:\Desktop\Science\Model\mmpose-main\Adam-mmdet-checkpoint\rtmdet_tiny_tang2\rtmdet_tiny_tang2.py",
    r"D:\Desktop\Science\Model\mmpose-main\Adam-mmdet-checkpoint\rtmdet_tiny_tang2\best_coco_bbox_mAP_epoch_198.pth",
    device=device
)

My guess:

If I use different model in mmlab at the same time, the later model(mmpose) will overridden the former model(Knet)

homomorfism commented 2 months ago

I have also encountered this bug, when migrating mmdet from 2.x to 3.x and mmseg from 0.x to 1.x

homomorfism commented 2 months ago

I have found solution in one of the issues: when you use difference mmlab frameworks for inference, use infer classes:

from mmdet.apis import DetInferencer
from mmseg.apis import MMSegInferencer

and etc.