File size: 1,759 Bytes
cea6d9d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python3
import os, sys, importlib.util, re

# ——— Monkey-patch mmdet to remove its mmcv-version assertion ———
spec = importlib.util.find_spec('mmdet')
if spec and spec.origin:
    src = open(spec.origin, encoding='utf-8').read()
    # strip out the mmcv_minimum_version…assert… block up to __all__
    patched = re.sub(r'(?ms)^[ \t]*mmcv_minimum_version.*?^__all__', '__all__', src)
    m = importlib.util.module_from_spec(spec)
    m.__loader__ = spec.loader
    m.__file__ = spec.origin
    m.__path__ = spec.submodule_search_locations
    sys.modules['mmdet'] = m
    exec(compile(patched, spec.origin, 'exec'), m.__dict__)

# ——— Configuration: set your image & output folder here ———
IMAGE_PATH = "000000197388.jpg"
VIS_OUT_DIR = "vis_results"
POSE2D = "rtmo"          # hard-code the RTMO 2D model alias
DEVICE = None            # e.g. "cuda:0" or None to auto-select

# ——— Inference ———
from mmpose.apis.inferencers import MMPoseInferencer

# create output folder
os.makedirs(VIS_OUT_DIR, exist_ok=True)

# instantiate the inferencer
inferencer = MMPoseInferencer(
    pose2d=POSE2D,
    scope="mmpose",
    device=DEVICE,
    det_cat_ids=[0],
    # you can override any other init args here…
)

# run on our single image, with the RTMO-specific defaults,
# iterating the generator so that visualization actually happens:
for result in inferencer(
    inputs=IMAGE_PATH,
    bbox_thr=0.1,
    nms_thr=0.65,
    pose_based_nms=True,
    show=False,
    vis_out_dir=VIS_OUT_DIR,
):
    # result is a dict with keys "visualization" and "predictions"
    # you can inspect it here if you like, e.g.:
    # print(result['predictions'])
    pass

print(f"Visualized results saved to {VIS_OUT_DIR}/")