RTMO ONNX Models from MMPOSE range from Tiny to Large
Browse files- convert_to_fp16.py +30 -0
- demo.sh +2 -0
- rtmo-l.fp16.onnx +3 -0
- rtmo-l.onnx +3 -0
- rtmo-m.fp16.onnx +3 -0
- rtmo-m.onnx +3 -0
- rtmo-s.fp16.onnx +3 -0
- rtmo-s.onnx +3 -0
- rtmo-t.fp16.onnx +3 -0
- rtmo-t.onnx +3 -0
- rtmo_demo.py +60 -0
- rtmo_gpu.py +55 -0
convert_to_fp16.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import argparse
|
2 |
+
from onnxmltools.utils.float16_converter import convert_float_to_float16
|
3 |
+
from onnxmltools.utils import load_model, save_model
|
4 |
+
|
5 |
+
def main():
|
6 |
+
# Set up an argument parser
|
7 |
+
parser = argparse.ArgumentParser(description='Convert ONNX model from Float32 to Float16.')
|
8 |
+
parser.add_argument('--input_model', type=str, required=True, help='Path to the input ONNX model file.')
|
9 |
+
parser.add_argument('--output_model', type=str, required=True, help='Path for saving the converted ONNX model file.')
|
10 |
+
|
11 |
+
# Parse arguments
|
12 |
+
args = parser.parse_args()
|
13 |
+
|
14 |
+
# Load the model
|
15 |
+
print(f"Loading model from {args.input_model}")
|
16 |
+
onnx_model = load_model(args.input_model)
|
17 |
+
|
18 |
+
# Convert model from Float32 to Float16
|
19 |
+
print("Converting model...")
|
20 |
+
new_onnx_model = convert_float_to_float16(onnx_model, keep_io_types=True)
|
21 |
+
|
22 |
+
# Save the converted model
|
23 |
+
print(f"Saving converted model to {args.output_model}")
|
24 |
+
save_model(new_onnx_model, args.output_model)
|
25 |
+
|
26 |
+
print("Conversion complete.")
|
27 |
+
|
28 |
+
if __name__ == "__main__":
|
29 |
+
main()
|
30 |
+
|
demo.sh
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
#!/bin/sh
|
2 |
+
python3 rtmo_demo.py ./video rtmo-t.fp16.onnx
|
rtmo-l.fp16.onnx
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:7252d22c1aa13abbd2b8616fb8468ba90465714719da9f8821c7fa25e6080aa2
|
3 |
+
size 88026530
|
rtmo-l.onnx
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:090096ca90f29163cc4f67137dcc0cd4b2ee95ea0af11764fbfda88dd2ae1140
|
3 |
+
size 175901910
|
rtmo-m.fp16.onnx
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b9bcaef995703f899258c04fd12a5bdd773e7f783e60d4b10b4a1a744caa1557
|
3 |
+
size 44704317
|
rtmo-m.onnx
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:750d872151ff4652f02c738efc3a547e112ce9b688fe920bc17f948e8c3afdac
|
3 |
+
size 89269977
|
rtmo-s.fp16.onnx
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:eda631cea4ce08c647dd76b835b290413191567acb0b2663c8e980318ef5d427
|
3 |
+
size 19871080
|
rtmo-s.onnx
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d0703d40d19f3921da51ae725402d5fdae4d2478c7442072d3101bd396f370d8
|
3 |
+
size 39617685
|
rtmo-t.fp16.onnx
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:4c45e15eb6609e4893697e5bf5ef2d40c8b6e15c77dbb30e72f148c2d0ca46ea
|
3 |
+
size 13733099
|
rtmo-t.onnx
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:20aad6e2e42359cac1c5b4a0b2da00e29bfe91a72a782fdcf287d273a04c1b24
|
3 |
+
size 27342008
|
rtmo_demo.py
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/python3
|
2 |
+
|
3 |
+
import time
|
4 |
+
import cv2
|
5 |
+
from rtmlib import draw_skeleton
|
6 |
+
from pathlib import Path
|
7 |
+
import argparse
|
8 |
+
import os
|
9 |
+
from rtmo_gpu import RTMO_GPU
|
10 |
+
|
11 |
+
if __name__ == "__main__":
|
12 |
+
|
13 |
+
# Set up argument parsing
|
14 |
+
parser = argparse.ArgumentParser(description='Process the path to a video file folder.')
|
15 |
+
parser.add_argument('path', type=str, help='Path to the folder containing video files (required)')
|
16 |
+
parser.add_argument('model_path', type=str, help='Path to a RTMO ONNX model file (required)')
|
17 |
+
|
18 |
+
# Parse the command-line arguments
|
19 |
+
args = parser.parse_args()
|
20 |
+
|
21 |
+
onnx_model = args.model_path # 'rtmo-s_8xb32-600e_body7-640x640.onnx'
|
22 |
+
|
23 |
+
# Only Tiny Model has (416,416) as input model
|
24 |
+
model_input_size = (416,416) if 'rtmo-t' in onnx_model.lower() else (640,640)
|
25 |
+
|
26 |
+
body = RTMO_GPU(onnx_model=onnx_model,
|
27 |
+
model_input_size=model_input_size)
|
28 |
+
|
29 |
+
for mp4_path in Path(args.path).glob('*'):
|
30 |
+
|
31 |
+
# Now, use the best.url, which is the direct video link for streaming
|
32 |
+
cap = cv2.VideoCapture(filename=os.path.abspath(mp4_path))
|
33 |
+
|
34 |
+
frame_idx = 0
|
35 |
+
|
36 |
+
while cap.isOpened():
|
37 |
+
success, frame = cap.read()
|
38 |
+
frame_idx += 1
|
39 |
+
|
40 |
+
if not success:
|
41 |
+
break
|
42 |
+
s = time.time()
|
43 |
+
keypoints, scores = body(frame)
|
44 |
+
det_time = time.time() - s
|
45 |
+
print(f'det: {round(1.0 / det_time,1)} FPS')
|
46 |
+
|
47 |
+
img_show = frame.copy()
|
48 |
+
|
49 |
+
# if you want to use black background instead of original image,
|
50 |
+
# img_show = np.zeros(img_show.shape, dtype=np.uint8)
|
51 |
+
|
52 |
+
img_show = draw_skeleton(img_show,
|
53 |
+
keypoints,
|
54 |
+
scores,
|
55 |
+
openpose_skeleton=False,
|
56 |
+
kpt_thr=0.3,
|
57 |
+
line_width=2)
|
58 |
+
img_show = cv2.resize(img_show, (788, 525))
|
59 |
+
cv2.imshow(f'{onnx_model}', img_show)
|
60 |
+
cv2.waitKey(10)
|
rtmo_gpu.py
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
from rtmlib import RTMO
|
3 |
+
|
4 |
+
class RTMO_GPU(RTMO):
|
5 |
+
|
6 |
+
def __init__(self,
|
7 |
+
onnx_model: str = None,
|
8 |
+
model_input_size: tuple = (640, 640),
|
9 |
+
mean: tuple = None,
|
10 |
+
std: tuple = None,
|
11 |
+
to_openpose: bool = False,
|
12 |
+
backend: str = 'onnxruntime',
|
13 |
+
device: str = 'cuda'):
|
14 |
+
|
15 |
+
if backend == 'onnxruntime':
|
16 |
+
|
17 |
+
if not os.path.exists(onnx_model):
|
18 |
+
from rtmlib.tools.file import download_checkpoint
|
19 |
+
onnx_model = download_checkpoint(onnx_model)
|
20 |
+
|
21 |
+
import onnxruntime as ort
|
22 |
+
|
23 |
+
providers = {'cpu': 'CPUExecutionProvider',
|
24 |
+
'cuda': [
|
25 |
+
('CUDAExecutionProvider', {
|
26 |
+
'device_id': 0,
|
27 |
+
'arena_extend_strategy': 'kNextPowerOfTwo',
|
28 |
+
'gpu_mem_limit': 2 * 1024 * 1024 * 1024,
|
29 |
+
'cudnn_conv_algo_search': 'DEFAULT',
|
30 |
+
'do_copy_in_default_stream': True,
|
31 |
+
'enable_cuda_graph': False
|
32 |
+
}),
|
33 |
+
'CPUExecutionProvider']}
|
34 |
+
|
35 |
+
self.session = ort.InferenceSession(path_or_bytes=onnx_model,
|
36 |
+
providers=providers[device])
|
37 |
+
|
38 |
+
print(f'load {onnx_model} with {backend} backend')
|
39 |
+
|
40 |
+
self.onnx_model = onnx_model
|
41 |
+
self.model_input_size = model_input_size
|
42 |
+
self.mean = mean
|
43 |
+
self.std = std
|
44 |
+
self.backend = backend
|
45 |
+
self.device = device
|
46 |
+
self.to_openpose = to_openpose
|
47 |
+
|
48 |
+
else:
|
49 |
+
super().__init__(onnx_model,
|
50 |
+
model_input_size,
|
51 |
+
mean,
|
52 |
+
std,
|
53 |
+
to_openpose,
|
54 |
+
backend,
|
55 |
+
device)
|