-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Update FMPose3D modelzoo integration #3221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
deruyter92
merged 24 commits into
DeepLabCut:main
from
deruyter92:jaap/fmpose_modelzoo_integration
Mar 20, 2026
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
8d8795c
Route FMPose3D through modelzoo video inference
deruyter92 c03fb2f
Move fmpose 3d module to pose_estimation_pytorch/modelzoo
deruyter92 34909b9
add dedicated FMPose3D video inference function
deruyter92 6d2eb0d
skip 3d predictions for invalid/empty 2d poses
deruyter92 785b55f
update tests
deruyter92 75f160c
Include 3d outputs in return
deruyter92 afc64a7
Clamp and warn: set max_individuals to 1
deruyter92 1f4cd90
change 3d data to dataframe
deruyter92 79306d6
add tests
deruyter92 04518bd
Update documentation
deruyter92 de1c573
Update modelzoo documentation fmpose3d
deruyter92 45f91b2
add commment legenda to __init__ for keypoint refactoring
deruyter92 a541c84
Add future note for keypoint refactoring
deruyter92 a96b8ca
fmpose3d: Add pytest markers for fmpose3d, unittest and functional
deruyter92 dd042b4
Apply formatting
deruyter92 1b3d94c
fix parameter name change in docs
deruyter92 8412c73
adjust parameter name -> fmpose_return_3d
deruyter92 ae8af5a
Update parameter naming superanimal_name
deruyter92 c0de52e
change recommended superanimal name for fmpose_3d
deruyter92 b771f33
Merge branch 'main' into jaap/fmpose_modelzoo_integration
deruyter92 8923015
Merge branch 'main' into jaap/fmpose_modelzoo_integration
deruyter92 f2c14c5
bump required version extra fmpose3d >= 0.0.8
deruyter92 9c78ddc
Merge branch 'main' into jaap/fmpose_modelzoo_integration
MMathisLab 18203b9
apply linting
deruyter92 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
deeplabcut/pose_estimation_pytorch/modelzoo/fmpose_3d/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| """ | ||
| DeepLabCut2.0-3.0 Toolbox (deeplabcut.org) | ||
| © A. & M. Mathis Labs | ||
| https://github.com/DeepLabCut/DeepLabCut | ||
| Please see AUTHORS for contributors. | ||
| https://github.com/DeepLabCut/DeepLabCut/blob/main/AUTHORS | ||
| Licensed under GNU Lesser General Public License v3.0 | ||
| """ | ||
|
|
||
| # NOTE: this module may contain items that need refactoring during | ||
| # the keypoint migration. | ||
|
|
||
| # kpt_refactor - Needs attention when refactoring keypoints | ||
| # i_o - This module writes keypoints to disk | ||
| # pandas - This module relies on pandas (might be moved to polars) |
137 changes: 137 additions & 0 deletions
137
deeplabcut/pose_estimation_pytorch/modelzoo/fmpose_3d/fmpose3d.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| """ | ||
| DeepLabCut2.0-3.0 Toolbox (deeplabcut.org) | ||
| © A. & M. Mathis Labs | ||
| https://github.com/DeepLabCut/DeepLabCut | ||
| Please see AUTHORS for contributors. | ||
| https://github.com/DeepLabCut/DeepLabCut/blob/main/AUTHORS | ||
| Licensed under GNU Lesser General Public License v3.0 | ||
| """ | ||
|
|
||
| from dataclasses import dataclass | ||
|
|
||
| from fmpose3d import ( | ||
| FMPose3DConfig, | ||
| FMPose3DInference, | ||
| SupportedModel, | ||
| ) | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class FMPose3DModelMetadata: | ||
| """Metadata for an FMPose3D model variant.""" | ||
|
|
||
| superanimal_name: str | ||
| bodyparts: tuple[str, ...] | ||
|
|
||
| @property | ||
| def num_bodyparts(self) -> int: | ||
| return len(self.bodyparts) | ||
|
|
||
| def build_model_cfg(self, max_individuals: int) -> dict: | ||
| """Build a DLC-compatible model_cfg dict for create_df_from_prediction.""" | ||
| return { | ||
| "metadata": { | ||
| "bodyparts": list(self.bodyparts), | ||
| "unique_bodyparts": [], | ||
| "individuals": [f"individual{i + 1}" for i in range(max_individuals)], | ||
| }, | ||
| } | ||
|
|
||
|
|
||
| FMPOSE3D_MODEL_METADATA: dict[str, FMPose3DModelMetadata] = { | ||
| "fmpose3d_humans": FMPose3DModelMetadata( | ||
| superanimal_name="superanimal_humanbody", | ||
| bodyparts=( | ||
| "pelvis", | ||
| "right_hip", | ||
| "right_knee", | ||
| "right_ankle", | ||
| "left_hip", | ||
| "left_knee", | ||
| "left_ankle", | ||
| "spine", | ||
| "thorax", | ||
| "neck", | ||
| "head", | ||
| "left_shoulder", | ||
| "left_elbow", | ||
| "left_wrist", | ||
| "right_shoulder", | ||
| "right_elbow", | ||
| "right_wrist", | ||
| ), | ||
| ), | ||
| "fmpose3d_animals": FMPose3DModelMetadata( | ||
| superanimal_name="superanimal_quadruped", | ||
| bodyparts=( | ||
| "left_eye", | ||
| "right_eye", | ||
| "nose", | ||
| "neck", | ||
| "root_of_tail", | ||
| "left_shoulder", | ||
| "left_elbow", | ||
| "left_front_paw", | ||
| "right_shoulder", | ||
| "right_elbow", | ||
| "right_front_paw", | ||
| "left_hip", | ||
| "left_knee", | ||
| "left_back_paw", | ||
| "right_hip", | ||
| "right_knee", | ||
| "right_back_paw", | ||
| "withers", | ||
| "throat", | ||
| "left_ear", | ||
| "right_ear", | ||
| "mouth", | ||
| "chin", | ||
| "left_hock", | ||
| "right_hock", | ||
| "tail_tip", | ||
| ), | ||
| ), | ||
| } | ||
|
|
||
|
|
||
| def get_fmpose3d_inference_api( | ||
| model_type: SupportedModel = "fmpose3d_humans", | ||
| snapshot_path: str | None = None, | ||
| device: str | None = None, | ||
| config_kwargs: dict = {}, | ||
| ) -> FMPose3DInference: | ||
| """ | ||
| Get a FMPose3DInference API for a given model type and snapshot path. | ||
|
|
||
| Args: | ||
| model_type: one of the supported model types: "fmpose3d_humans", "fmpose3d_animals", | ||
| snapshot_path: The path to the snapshot file. If None, FMPose3D will download the default snapshot. | ||
| device: The device to use. If None, the device will be inferred from the environment. | ||
| config_kwargs: Additional keyword arguments to pass to the FMPose3DConfig. | ||
| Returns: | ||
| FMPose3DInference: An FMPose3DInference API runner. | ||
|
|
||
| Example Usages | ||
| ```python | ||
| # Initialize the API (downloads the default weights automatically from huggingface) | ||
| fmpose = get_fmpose3d_inference_api( | ||
| model_type="fmpose3d_animals", | ||
| device="cuda:0", | ||
| ) | ||
|
|
||
| # Run inference on an image | ||
| predictions_3d = fmpose.predict(source="path/to/image.jpg") # or (H, W, 3) numpy array | ||
|
|
||
| # Lift 2d predictions to 3d | ||
| keypoints_2d = np.random.rand(num_frames, num_joints, 2) | ||
| predictions_3d = fmpose.pose_3d(keypoints_2d=keypoints_2d) | ||
| ``` | ||
| """ | ||
| model_config = FMPose3DConfig(model_type=model_type, **config_kwargs) | ||
| fmpose3d_api = FMPose3DInference( | ||
| model_config, | ||
| model_weights_path=snapshot_path, | ||
| device=device, | ||
| ) | ||
| return fmpose3d_api |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.