Spaces:
Running
on
Zero
Running
on
Zero
standalone demo script with cpu
Browse files- demo.py +53 -0
- requirements.txt +9 -0
demo.py
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
import os, sys, importlib.util, re
|
3 |
+
|
4 |
+
# ——— Monkey-patch mmdet to remove its mmcv-version assertion ———
|
5 |
+
spec = importlib.util.find_spec('mmdet')
|
6 |
+
if spec and spec.origin:
|
7 |
+
src = open(spec.origin, encoding='utf-8').read()
|
8 |
+
# strip out the mmcv_minimum_version…assert… block up to __all__
|
9 |
+
patched = re.sub(r'(?ms)^[ \t]*mmcv_minimum_version.*?^__all__', '__all__', src)
|
10 |
+
m = importlib.util.module_from_spec(spec)
|
11 |
+
m.__loader__ = spec.loader
|
12 |
+
m.__file__ = spec.origin
|
13 |
+
m.__path__ = spec.submodule_search_locations
|
14 |
+
sys.modules['mmdet'] = m
|
15 |
+
exec(compile(patched, spec.origin, 'exec'), m.__dict__)
|
16 |
+
|
17 |
+
# ——— Configuration: set your image & output folder here ———
|
18 |
+
IMAGE_PATH = "000000197388.jpg"
|
19 |
+
VIS_OUT_DIR = "vis_results"
|
20 |
+
POSE2D = "rtmo" # hard-code the RTMO 2D model alias
|
21 |
+
DEVICE = None # e.g. "cuda:0" or None to auto-select
|
22 |
+
|
23 |
+
# ——— Inference ———
|
24 |
+
from mmpose.apis.inferencers import MMPoseInferencer
|
25 |
+
|
26 |
+
# create output folder
|
27 |
+
os.makedirs(VIS_OUT_DIR, exist_ok=True)
|
28 |
+
|
29 |
+
# instantiate the inferencer
|
30 |
+
inferencer = MMPoseInferencer(
|
31 |
+
pose2d=POSE2D,
|
32 |
+
scope="mmpose",
|
33 |
+
device=DEVICE,
|
34 |
+
det_cat_ids=[0],
|
35 |
+
# you can override any other init args here…
|
36 |
+
)
|
37 |
+
|
38 |
+
# run on our single image, with the RTMO-specific defaults,
|
39 |
+
# iterating the generator so that visualization actually happens:
|
40 |
+
for result in inferencer(
|
41 |
+
inputs=IMAGE_PATH,
|
42 |
+
bbox_thr=0.1,
|
43 |
+
nms_thr=0.65,
|
44 |
+
pose_based_nms=True,
|
45 |
+
show=False,
|
46 |
+
vis_out_dir=VIS_OUT_DIR,
|
47 |
+
):
|
48 |
+
# result is a dict with keys "visualization" and "predictions"
|
49 |
+
# you can inspect it here if you like, e.g.:
|
50 |
+
# print(result['predictions'])
|
51 |
+
pass
|
52 |
+
|
53 |
+
print(f"Visualized results saved to {VIS_OUT_DIR}/")
|
requirements.txt
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
--find-links https://download.openmmlab.com/mmcv/dist/cpu/torch2.4/index.html
|
2 |
+
mmcv==2.2.0
|
3 |
+
torch==2.4.0
|
4 |
+
opencv-python
|
5 |
+
numpy
|
6 |
+
mmengine
|
7 |
+
mmdet
|
8 |
+
mmpose
|
9 |
+
gradio
|