Skip to content

Commit b0f72a6

Browse files
committed
Smarter 'auto" number of workers for pose estimation. Allows for Ctrl+C interruption. Implemented parallelization of kinematics.
1 parent 2f27952 commit b0f72a6

10 files changed

Lines changed: 155 additions & 79 deletions

File tree

Pose2Sim/Demo_Batch/Config.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ det_frequency = 4 # Run person detection only every N frames, and inbetween trac
7979
# Equal to or greater than 1, can be as high as you want in simple uncrowded cases. Much faster, but might be less accurate.
8080
device = 'auto' # 'auto', 'CPU', 'CUDA', 'MPS', 'ROCM'
8181
backend = 'auto' # 'auto', 'openvino', 'onnxruntime', 'opencv'
82-
parallel_pose = 'auto' # 'auto' or integer (number of threads). 'auto': one thread per video (ie 4 on the Demo data).
83-
# Requires display_detection = false, otherwise falls back to sequential (ie parallel_pose = 1).
82+
parallel_workers_pose = 'auto' # 'auto', int, or false # One worker per video, using GPU if available
83+
# Requires display_detection = false, otherwise falls back to sequential (ie parallel_workers_pose = 1/false).
8484

8585
display_detection = false # Real-time display of the videos with pose estimation
8686
overwrite_pose = false # Set to false if you don't want to recalculate pose estimation when it has already been done
@@ -193,7 +193,8 @@ calibration_type = 'convert' # 'convert' or 'calculate'
193193
# for each frame, each keypoint: if results are not good, we remove a camera and try again
194194
reproj_error_threshold_triangulation = 15 # px # if reprojection error is above, triangulation results won't be accepted
195195
likelihood_threshold_triangulation= 0.3 # if 2D likelihood is below, estimations for this camera won't be accepted
196-
min_cameras_for_triangulation = 2 # won't try below N cameras if the triangulation is still not good
196+
min_cameras_for_triangulation = 2 # stops trying to triangulate if results still not good with min_cameras_for_triangulation cameras.
197+
# Increase if you have many cameras and want to be more robust to occlusions
197198

198199
# gap filling
199200
max_distance_m = 1.0 # m # max_distance a person can jump from its previous position before being considered as a new one
@@ -263,6 +264,7 @@ make_c3d = true # save triangulated data in c3d format in addition to trc
263264

264265

265266
[kinematics]
267+
parallel_workers_kinematics = 'auto' # 'auto', int, or false # One worker per person, uses CPU. Only available in multi-person mode.
266268
use_augmentation = true # true or false (lowercase) # Set to true if you want to use the model with augmented markers
267269
use_simple_model = false # true or false # >10 times faster IK if true. No muscles, no constraints (eg stiff spine and shoulders, no patella)
268270
right_left_symmetry = true # true or false (lowercase) # Set to false only if you have good reasons to think the participant is not symmetrical (e.g. prosthetic limb)

Pose2Sim/Demo_Batch/Trial_1/Config.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@
7878
# # Equal to or greater than 1, can be as high as you want in simple uncrowded cases. Much faster, but might be less accurate.
7979
# device = 'auto' # 'auto', 'CPU', 'CUDA', 'MPS', 'ROCM'
8080
# backend = 'auto' # 'auto', 'openvino', 'onnxruntime', 'opencv'
81-
# parallel_pose = 'auto' # 'auto' or integer (number of threads). 'auto': one thread per video (ie 4 on the Demo data).
82-
# # Requires display_detection = false, otherwise falls back to sequential (ie parallel_pose = 1).
81+
# parallel_workers_pose = 'auto' # 'auto', int, or false # One worker per video, using GPU if available
82+
# # Requires display_detection = false, otherwise falls back to sequential (ie parallel_workers_pose = 1/false).
8383

8484
# display_detection = true # Real-time display of the videos with pose estimation
8585
# overwrite_pose = false # Set to false if you don't want to recalculate pose estimation when it has already been done
@@ -193,7 +193,8 @@
193193
# # for each frame, each keypoint: if results are not good, we remove a camera and try again
194194
# reproj_error_threshold_triangulation = 15 # px # if reprojection error is above, triangulation results won't be accepted
195195
# likelihood_threshold_triangulation= 0.3 # if 2D likelihood is below, estimations for this camera won't be accepted
196-
# min_cameras_for_triangulation = 2 # won't try below N cameras if the triangulation is still not good
196+
# min_cameras_for_triangulation = 2 # stops trying to triangulate if results still not good with min_cameras_for_triangulation cameras.
197+
# Increase if you have many cameras and want to be more robust to occlusions
197198

198199
# # gap filling
199200
# max_distance_m = 1.0 # m # max_distance a person can jump from its previous position before being considered as a new one
@@ -263,6 +264,7 @@
263264

264265

265266
# [kinematics]
267+
# parallel_workers_kinematics = 'auto' # 'auto', int, or false # One worker per person, uses CPU. Only available in multi-person mode.
266268
# use_augmentation = true # true or false (lowercase) # Set to true if you want to use the model with augmented markers
267269
# use_simple_model = false # true or false # >10 times faster IK if true. No muscles, no constraints (eg stiff spine and shoulders, no patella)
268270
# right_left_symmetry = true # true or false (lowercase) # Set to false only if you have good reasons to think the participant is not symmetrical (e.g. prosthetic limb)

Pose2Sim/Demo_Batch/Trial_2/Config.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ participant_mass = [70.0, 63.5] # float (eg 70.0), or list of floats (eg [70
7777
# # Equal to or greater than 1, can be as high as you want in simple uncrowded cases. Much faster, but might be less accurate.
7878
# device = 'auto' # 'auto', 'CPU', 'CUDA', 'MPS', 'ROCM'
7979
# backend = 'auto' # 'auto', 'openvino', 'onnxruntime', 'opencv'
80-
# parallel_pose = 'auto' # 'auto' or integer (number of threads). 'auto': one thread per video (ie 4 on the Demo data).
81-
# # Requires display_detection = false, otherwise falls back to sequential (ie parallel_pose = 1).
80+
# parallel_workers_pose = 'auto' # 'auto', int, or false # One worker per video, using GPU if available
81+
# # Requires display_detection = false, otherwise falls back to sequential (ie parallel_workers_pose = 1/false).
8282

8383
# display_detection = true # Real-time display of the videos with pose estimation
8484
# overwrite_pose = false # Set to false if you don't want to recalculate pose estimation when it has already been done
@@ -191,7 +191,8 @@ keypoints_to_consider = ['RWrist'] # 'all' if all points should be considered, f
191191
# # for each frame, each keypoint: if results are not good, we remove a camera and try again
192192
# reproj_error_threshold_triangulation = 15 # px # if reprojection error is above, triangulation results won't be accepted
193193
# likelihood_threshold_triangulation= 0.3 # if 2D likelihood is below, estimations for this camera won't be accepted
194-
# min_cameras_for_triangulation = 2 # won't try below N cameras if the triangulation is still not good
194+
# min_cameras_for_triangulation = 2 # stops trying to triangulate if results still not good with min_cameras_for_triangulation cameras.
195+
# Increase if you have many cameras and want to be more robust to occlusions
195196

196197
# # gap filling
197198
# max_distance_m = 1.0 # m # max_distance a person can jump from its previous position before being considered as a new one
@@ -261,6 +262,7 @@ keypoints_to_consider = ['RWrist'] # 'all' if all points should be considered, f
261262

262263

263264
# [kinematics]
265+
# parallel_workers_kinematics = 'auto' # 'auto', int, or false # One worker per person, uses CPU. Only available in multi-person mode.
264266
# use_augmentation = true # true or false (lowercase) # Set to true if you want to use the model with augmented markers
265267
# use_simple_model = false # true or false # >10 times faster IK if true. No muscles, no constraints (eg stiff spine and shoulders, no patella)
266268
# right_left_symmetry = true # true or false (lowercase) # Set to false only if you have good reasons to think the participant is not symmetrical (e.g. prosthetic limb)

Pose2Sim/Demo_MultiPerson/Config.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ det_frequency = 4 # Run person detection only every N frames, and inbetween trac
7979
# Equal to or greater than 1, can be as high as you want in simple uncrowded cases. Much faster, but might be less accurate.
8080
device = 'auto' # 'auto', 'CPU', 'CUDA', 'MPS', 'ROCM'
8181
backend = 'auto' # 'auto', 'openvino', 'onnxruntime', 'opencv'
82-
parallel_pose = 'auto' # 'auto' or integer (number of threads). 'auto': one thread per video (ie 4 on the Demo data).
83-
# Requires display_detection = false, otherwise falls back to sequential (ie parallel_pose = 1).
82+
parallel_workers_pose = 'auto' # 'auto', int, or false # One worker per video, using GPU if available
83+
# Requires display_detection = false, otherwise falls back to sequential (ie parallel_workers_pose = 1/false).
8484

8585
display_detection = true # Real-time display of the videos with pose estimation
8686
overwrite_pose = false # Set to false if you don't want to recalculate pose estimation when it has already been done
@@ -193,7 +193,8 @@ calibration_type = 'convert' # 'convert' or 'calculate'
193193
# for each frame, each keypoint: if results are not good, we remove a camera and try again
194194
reproj_error_threshold_triangulation = 15 # px # if reprojection error is above, triangulation results won't be accepted
195195
likelihood_threshold_triangulation= 0.3 # if 2D likelihood is below, estimations for this camera won't be accepted
196-
min_cameras_for_triangulation = 2 # won't try below N cameras if the triangulation is still not good
196+
min_cameras_for_triangulation = 2 # stops trying to triangulate if results still not good with min_cameras_for_triangulation cameras.
197+
# Increase if you have many cameras and want to be more robust to occlusions
197198

198199
# gap filling
199200
max_distance_m = 1.0 # m # max_distance a person can jump from its previous position before being considered as a new one
@@ -265,6 +266,7 @@ make_c3d = true # save triangulated data in c3d format in addition to trc
265266
[kinematics]
266267
use_augmentation = true # true or false (lowercase) # Set to true if you want to use the model with augmented markers
267268
use_simple_model = false # true or false # >10 times faster IK if true. No muscles, no constraints (eg stiff spine and shoulders, no patella)
269+
parallel_workers_kinematics = 'auto' # 'auto', int, or false # One worker per person, uses CPU. Only available in multi-person mode.
268270
right_left_symmetry = true # true or false (lowercase) # Set to false only if you have good reasons to think the participant is not symmetrical (e.g. prosthetic limb)
269271

270272
default_height = 1.7 # meters # If automatic height calculation did not work, this value is used to scale the model

Pose2Sim/Demo_SinglePerson/Config.toml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,9 @@ det_frequency = 4 # Run person detection only every N frames, and inbetween trac
7777
# Equal to or greater than 1, can be as high as you want in simple uncrowded cases. Much faster, but might be less accurate.
7878
device = 'auto' # 'auto', 'CPU', 'CUDA', 'MPS', 'ROCM'
7979
backend = 'auto' # 'auto', 'openvino', 'onnxruntime', 'opencv'
80-
parallel_pose = 'auto' # 'auto' or integer (number of threads). 'auto': one thread per video (ie 4 on the Demo data).
81-
# Requires display_detection = false, otherwise falls back to sequential (ie parallel_pose = 1).
82-
83-
display_detection = true # Real-time display of the videos with pose estimation
80+
parallel_workers_pose = 'auto' # 'auto', int, or false # One worker per video, using GPU if available
81+
# Requires display_detection = false, otherwise falls back to sequential (ie parallel_workers_pose = 1/false).
82+
display_detection = true # Real-time display of the videos with pose estimation. Set to false for parallel processing.
8483
overwrite_pose = false # Set to false if you don't want to recalculate pose estimation when it has already been done
8584
save_video = 'to_video' # 'to_video' or 'to_images', 'none', or ['to_video', 'to_images']
8685
output_format = 'openpose' # 'openpose', 'mmpose', 'deeplabcut', 'none' or a list of them # /!\ only 'openpose' is supported for now
@@ -192,7 +191,8 @@ calibration_type = 'convert' # 'convert' or 'calculate'
192191
# for each frame, each keypoint: if results are not good, we remove a camera and try again
193192
reproj_error_threshold_triangulation = 15 # px # if reprojection error is above, triangulation results won't be accepted
194193
likelihood_threshold_triangulation= 0.3 # if 2D likelihood is below, estimations for this camera won't be accepted
195-
min_cameras_for_triangulation = 2 # won't try below N cameras if the triangulation is still not good
194+
min_cameras_for_triangulation = 2 # stops trying to triangulate if results still not good with min_cameras_for_triangulation cameras.
195+
# Increase if you have many cameras and want to be more robust to occlusions
196196

197197
# gap filling
198198
max_distance_m = 1.0 # m # max_distance a person can jump from its previous position before being considered as a new one
@@ -264,6 +264,7 @@ make_c3d = true # save triangulated data in c3d format in addition to trc
264264
[kinematics]
265265
use_augmentation = true # true or false (lowercase) # Set to true if you want to use the model with augmented markers
266266
use_simple_model = false # true or false # >10 times faster IK if true. No muscles, no constraints (eg stiff spine and shoulders, no patella)
267+
parallel_workers_kinematics = 'auto' # 'auto', int, or false # One worker per person, uses CPU. Only available in multi-person mode.
267268
right_left_symmetry = true # true or false (lowercase) # Set to false only if you have good reasons to think the participant is not symmetrical (e.g. prosthetic limb)
268269

269270
default_height = 1.7 # meters # If automatic height calculation did not work, this value is used to scale the model

Pose2Sim/Utilities/tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def test_workflow(self, mock_input):
142142
config_dict.get("project").update({"frame_rate":60})
143143
config_dict.get("pose").update({"det_frequency":10})
144144
config_dict.get("pose").update({"mode":'balanced'})
145-
config_dict.get("pose").update({"parallel_pose":1})
145+
config_dict.get("pose").update({"parallel_workers_pose":2})
146146
config_dict.get("pose").update({"overwrite_pose":True})
147147
config_dict.get("pose").update({"save_video":'none'})
148148
config_dict.get('synchronization').update({'keypoints_to_consider':['RWrist']})

Pose2Sim/common.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,37 @@ def is_image_file(path):
190190
return os.path.isfile(path) and os.path.splitext(path)[1].lower() in image_extensions
191191

192192

193+
def get_max_workers(device='cpu'):
194+
'''
195+
Determine the number of parallel workers for pose estimation.
196+
197+
INPUTS:
198+
device: 'cpu', 'cuda', 'mps', 'rocm'
199+
200+
OUTPUTS:
201+
max_workers: Number of workers (>= 1)
202+
'''
203+
204+
if device == 'cpu':
205+
# Half of the CPU cores
206+
cpu_count = os.cpu_count() or 4
207+
max_workers = max(1, cpu_count // 2)
208+
209+
else:
210+
# ~1 GB per worker, 20% headroom
211+
try:
212+
# 'cuda' or 'rocm'
213+
import torch
214+
vram_gb = torch.cuda.mem_get_info(0)[0] / 1e9
215+
max_workers = max(1, int(vram_gb * 0.8))
216+
except Exception:
217+
# 'mps' or fallback
218+
max_workers = 4
219+
220+
return max_workers
221+
222+
223+
193224
def read_trc(trc_path):
194225
'''
195226
Read a TRC file and extract its contents.

0 commit comments

Comments
 (0)