Spaces:
Runtime error
Runtime error
Graceful fallback when motion_correction missing
Browse files- kimodo/postprocess.py +28 -4
kimodo/postprocess.py
CHANGED
|
@@ -2,6 +2,8 @@
|
|
| 2 |
# SPDX-License-Identifier: Apache-2.0
|
| 3 |
"""Post-processing utilities for motion generation output."""
|
| 4 |
|
|
|
|
|
|
|
| 5 |
from types import SimpleNamespace
|
| 6 |
from typing import Dict, List, Optional, Tuple
|
| 7 |
|
|
@@ -23,6 +25,15 @@ from .skeleton import (
|
|
| 23 |
fk,
|
| 24 |
)
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
def extract_input_motion_from_constraints(
|
| 28 |
constraint_lst: List,
|
|
@@ -307,10 +318,23 @@ def post_process_motion(
|
|
| 307 |
try:
|
| 308 |
from motion_correction import motion_postprocess
|
| 309 |
except ImportError as e:
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 314 |
for b in range(batch_size):
|
| 315 |
masks_b = constraint_masks_dict_lst[b] if batched_constraints else constraint_masks_dict
|
| 316 |
motion_postprocess.correct_motion(
|
|
|
|
| 2 |
# SPDX-License-Identifier: Apache-2.0
|
| 3 |
"""Post-processing utilities for motion generation output."""
|
| 4 |
|
| 5 |
+
import logging
|
| 6 |
+
import os
|
| 7 |
from types import SimpleNamespace
|
| 8 |
from typing import Dict, List, Optional, Tuple
|
| 9 |
|
|
|
|
| 25 |
fk,
|
| 26 |
)
|
| 27 |
|
| 28 |
+
logger = logging.getLogger(__name__)
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def _env_bool(name: str, default: bool = False) -> bool:
|
| 32 |
+
raw = os.environ.get(name)
|
| 33 |
+
if raw is None:
|
| 34 |
+
return default
|
| 35 |
+
return str(raw).strip().lower() in {"1", "true", "yes", "on"}
|
| 36 |
+
|
| 37 |
|
| 38 |
def extract_input_motion_from_constraints(
|
| 39 |
constraint_lst: List,
|
|
|
|
| 318 |
try:
|
| 319 |
from motion_correction import motion_postprocess
|
| 320 |
except ImportError as e:
|
| 321 |
+
if _env_bool("KIMODO_STRICT_MOTION_CORRECTION", default=False):
|
| 322 |
+
raise RuntimeError(
|
| 323 |
+
"Motion correction is required for this postprocessing path but the "
|
| 324 |
+
"motion_correction package is not installed. Install with: pip install -e ."
|
| 325 |
+
) from e
|
| 326 |
+
|
| 327 |
+
logger.warning(
|
| 328 |
+
"motion_correction package is not installed; skipping correction and returning "
|
| 329 |
+
"uncorrected motion. Set KIMODO_STRICT_MOTION_CORRECTION=true to fail instead."
|
| 330 |
+
)
|
| 331 |
+
global_rot_mats, posed_joints, _ = fk(local_rot_mats, root_positions, skeleton)
|
| 332 |
+
return {
|
| 333 |
+
"local_rot_mats": local_rot_mats,
|
| 334 |
+
"root_positions": root_positions,
|
| 335 |
+
"posed_joints": posed_joints,
|
| 336 |
+
"global_rot_mats": global_rot_mats,
|
| 337 |
+
}
|
| 338 |
for b in range(batch_size):
|
| 339 |
masks_b = constraint_masks_dict_lst[b] if batched_constraints else constraint_masks_dict
|
| 340 |
motion_postprocess.correct_motion(
|