-
Notifications
You must be signed in to change notification settings - Fork 11
Add huggingface functionality #18
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
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7bd29c1
Add huggingface functionality
deruyter92 a20e9d4
update pytests: add huggingface and end-to-end functional tests
deruyter92 cb25699
Update headers
deruyter92 f61efa5
Move inference_api to separate folder
deruyter92 9cbf7ca
Add api documentation
deruyter92 49ae00e
update header
deruyter92 980bebb
change HF_REPO_ID to DeepLabCut/FMPose3D
deruyter92 273c8fc
Fix import path in tests for huggingface model weight downloads
xiu-cs 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 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
Empty file.
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,8 @@ | ||
| """ | ||
| FMPose3D: monocular 3D Pose Estimation via Flow Matching | ||
|
|
||
| Official implementation of the paper: | ||
| "FMPose3D: monocular 3D Pose Estimation via Flow Matching" | ||
| by Ti Wang, Xiaohang Yu, and Mackenzie Weygandt Mathis | ||
| Licensed under Apache 2.0 | ||
| """ |
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,104 @@ | ||
| """ | ||
| FMPose3D: monocular 3D Pose Estimation via Flow Matching | ||
|
|
||
| Official implementation of the paper: | ||
| "FMPose3D: monocular 3D Pose Estimation via Flow Matching" | ||
| by Ti Wang, Xiaohang Yu, and Mackenzie Weygandt Mathis | ||
| Licensed under Apache 2.0 | ||
|
|
||
| Shared fixtures, markers, and skip-helpers for the ``fmpose3d_api`` test suite. | ||
|
|
||
| Skip logic | ||
| ---------- | ||
| * **weights_ready(filename)** – ``True`` when the HuggingFace-cached file | ||
| already exists on disk *or* we can reach ``huggingface.co`` so that | ||
| ``hf_hub_download`` will succeed. | ||
| * **has_internet** – evaluated once at collection time via a quick TCP probe. | ||
| * **HF_HUB_OFFLINE** – if set to ``"1"`` in the environment the network | ||
| check is skipped entirely (consistent with how ``huggingface_hub`` | ||
| itself behaves). | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import os | ||
| import socket | ||
|
|
||
| import pytest | ||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # HuggingFace repo & filenames (must match fmpose3d.fmpose3d._HF_REPO_ID) | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
| HF_REPO_ID: str = "deruyter92/fmpose_temp" | ||
|
|
||
| HUMAN_WEIGHTS_FILENAME: str = "fmpose3d_humans.pth" | ||
| ANIMAL_WEIGHTS_FILENAME: str = "fmpose3d_animals.pth" | ||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # Connectivity helpers | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
|
|
||
| def _has_internet(host: str = "huggingface.co", port: int = 443, timeout: float = 3) -> bool: | ||
| """Return ``True`` if *host* is reachable via TCP.""" | ||
| if os.environ.get("HF_HUB_OFFLINE", "0") == "1": | ||
| return False | ||
| try: | ||
| socket.create_connection((host, port), timeout=timeout) | ||
| return True | ||
| except OSError: | ||
| return False | ||
|
|
||
|
|
||
| def _weights_cached(filename: str) -> bool: | ||
| """Return ``True`` if *filename* already lives in the local HF cache.""" | ||
| try: | ||
| from huggingface_hub import try_to_load_from_cache | ||
|
|
||
| result = try_to_load_from_cache(HF_REPO_ID, filename) | ||
| return isinstance(result, str) | ||
| except Exception: | ||
| return False | ||
|
|
||
|
|
||
| def weights_ready(filename: str) -> bool: | ||
| """``True`` when we can obtain *filename* — either from cache or network.""" | ||
| return _weights_cached(filename) or _has_internet() | ||
|
|
||
|
|
||
| # Evaluate once at collection time. | ||
| HAS_INTERNET: bool = _has_internet() | ||
| HUMAN_WEIGHTS_READY: bool = weights_ready(HUMAN_WEIGHTS_FILENAME) | ||
| ANIMAL_WEIGHTS_READY: bool = weights_ready(ANIMAL_WEIGHTS_FILENAME) | ||
|
|
||
| try: | ||
| import deeplabcut # noqa: F401 | ||
|
|
||
| DLC_AVAILABLE: bool = True | ||
| except ImportError: | ||
| DLC_AVAILABLE = False | ||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # Reusable skip markers | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
| requires_network = pytest.mark.skipif( | ||
| not HAS_INTERNET, | ||
| reason="No internet connection (cannot reach huggingface.co)", | ||
| ) | ||
|
|
||
| requires_human_weights = pytest.mark.skipif( | ||
| not HUMAN_WEIGHTS_READY, | ||
| reason="Human weights not cached and no internet connection", | ||
| ) | ||
|
|
||
| requires_animal_weights = pytest.mark.skipif( | ||
| not ANIMAL_WEIGHTS_READY, | ||
| reason="Animal weights not cached and no internet connection", | ||
| ) | ||
|
|
||
| requires_dlc = pytest.mark.skipif( | ||
| not DLC_AVAILABLE, | ||
| reason="DeepLabCut is not installed", | ||
| ) | ||
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.