Return a local weights path, downloading from Hugging Face Hub if needed. Parameters ---------- model_weights_path : str User-supplied local path. If falsy the weights are fetched from the Hugging Face Hub automatically. model_type : str Model variant name u
(model_weights_path: str, model_type: str)
| 13 | |
| 14 | |
| 15 | def resolve_weights_path(model_weights_path: str, model_type: str) -> str: |
| 16 | """Return a local weights path, downloading from Hugging Face Hub if needed. |
| 17 | |
| 18 | Parameters |
| 19 | ---------- |
| 20 | model_weights_path : str |
| 21 | User-supplied local path. If falsy the weights are fetched from the |
| 22 | Hugging Face Hub automatically. |
| 23 | model_type : str |
| 24 | Model variant name used to derive the remote filename |
| 25 | (e.g. ``"fmpose3d_humans"`` -> ``fmpose3d_humans.pth``). |
| 26 | |
| 27 | Returns |
| 28 | ------- |
| 29 | str |
| 30 | Absolute path to the weight file on disk. |
| 31 | """ |
| 32 | if model_weights_path: |
| 33 | return model_weights_path |
| 34 | |
| 35 | try: |
| 36 | from huggingface_hub import hf_hub_download |
| 37 | except ImportError: |
| 38 | raise ImportError( |
| 39 | "huggingface_hub is required to download model weights. " |
| 40 | "Install it with: pip install huggingface_hub\n" |
| 41 | "Or download the weights manually and pass the local path." |
| 42 | ) from None |
| 43 | |
| 44 | filename = f"{model_type}.pth" |
| 45 | print( |
| 46 | f"No local weights path specified. " |
| 47 | f"Downloading '{filename}' from Hugging Face ({HF_REPO_ID})..." |
| 48 | ) |
| 49 | return hf_hub_download(repo_id=HF_REPO_ID, filename=filename) |
no outgoing calls
no test coverage detected