Skip to content

Commit ccf29a9

Browse files
committed
Add high-level inference API for FMPose3D (fmpose3d/fmpose3d.py)
1 parent 3f905ad commit ccf29a9

3 files changed

Lines changed: 726 additions & 0 deletions

File tree

fmpose3d/__init__.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,43 @@
1818
aggregation_RPEA_joint_level,
1919
)
2020

21+
# Configuration dataclasses
22+
from .common.config import (
23+
FMPose3DConfig,
24+
HRNetConfig,
25+
InferenceConfig,
26+
ModelConfig,
27+
PipelineConfig,
28+
)
29+
30+
# High-level inference API
31+
from .fmpose3d import (
32+
FMPose3DInference,
33+
HRNetEstimator,
34+
Pose2DResult,
35+
Pose3DResult,
36+
Source,
37+
)
38+
2139
# Import 2D pose detection utilities
2240
from .lib.hrnet.gen_kpts import gen_video_kpts
2341
from .lib.hrnet.hrnet import HRNetPose2d
2442
from .lib.preprocess import h36m_coco_format, revise_kpts
2543

2644
# Make commonly used classes/functions available at package level
2745
__all__ = [
46+
# Inference API
47+
"FMPose3DInference",
48+
"HRNetEstimator",
49+
"Pose2DResult",
50+
"Pose3DResult",
51+
"Source",
52+
# Configuration
53+
"FMPose3DConfig",
54+
"HRNetConfig",
55+
"InferenceConfig",
56+
"ModelConfig",
57+
"PipelineConfig",
2858
# Aggregation methods
2959
"average_aggregation",
3060
"aggregation_select_single_best_hypothesis_by_2D_error",

fmpose3d/common/utils.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,44 @@
1616
import numpy as np
1717
import torch
1818

19+
20+
def euler_sample(
21+
c_2d: torch.Tensor,
22+
y: torch.Tensor,
23+
steps: int,
24+
model: torch.nn.Module,
25+
) -> torch.Tensor:
26+
"""Euler ODE sampler for Conditional Flow Matching at test time.
27+
28+
Integrates the learned velocity field from *t = 0* to *t = 1* using
29+
``steps`` uniform Euler steps.
30+
31+
Parameters
32+
----------
33+
c_2d : Tensor
34+
2-D conditioning input, shape ``(B, F, J, 2)``.
35+
y : Tensor
36+
Initial noise sample (same spatial dims as ``c_2d`` but with 3
37+
output channels), shape ``(B, F, J, 3)``.
38+
steps : int
39+
Number of Euler integration steps.
40+
model : nn.Module
41+
The velocity-prediction network ``v(c_2d, y, t)``.
42+
43+
Returns
44+
-------
45+
Tensor
46+
The denoised 3-D prediction, same shape as *y*.
47+
"""
48+
dt = 1.0 / steps
49+
for s in range(steps):
50+
t_s = torch.full(
51+
(c_2d.size(0), 1, 1, 1), s * dt, device=c_2d.device, dtype=c_2d.dtype
52+
)
53+
v_s = model(c_2d, y, t_s)
54+
y = y + dt * v_s
55+
return y
56+
1957
def deterministic_random(min_value, max_value, data):
2058
digest = hashlib.sha256(data.encode()).digest()
2159
raw_value = int.from_bytes(digest[:4], byteorder="little", signed=False)

0 commit comments

Comments
 (0)