Builds the WeightInitialization from a SuperAnimal model for a project. Args: cfg: The project's configuration, or the path to the project configuration file. super_animal: The SuperAnimal model with which to initialize weights. model_name: The type of the model architec
(
cfg: dict | str | Path,
super_animal: str,
model_name: str,
detector_name: str | None,
with_decoder: bool = False,
memory_replay: bool = False,
customized_pose_checkpoint: str | Path | None = None,
customized_detector_checkpoint: str | Path | None = None,
)
| 21 | |
| 22 | |
| 23 | def build_weight_init( |
| 24 | cfg: dict | str | Path, |
| 25 | super_animal: str, |
| 26 | model_name: str, |
| 27 | detector_name: str | None, |
| 28 | with_decoder: bool = False, |
| 29 | memory_replay: bool = False, |
| 30 | customized_pose_checkpoint: str | Path | None = None, |
| 31 | customized_detector_checkpoint: str | Path | None = None, |
| 32 | ) -> WeightInitialization: |
| 33 | """Builds the WeightInitialization from a SuperAnimal model for a project. |
| 34 | |
| 35 | Args: |
| 36 | cfg: The project's configuration, or the path to the project configuration file. |
| 37 | super_animal: The SuperAnimal model with which to initialize weights. |
| 38 | model_name: The type of the model architecture for which to load the weights. |
| 39 | detector_name: The type of detector architecture for which to load the weights. |
| 40 | with_decoder: Whether to load the decoder weights as well. If this is true, |
| 41 | a conversion table must be specified for the given SuperAnimal in the |
| 42 | project configuration file. See |
| 43 | ``deeplabcut.modelzoo.utils.create_conversion_table`` to create a |
| 44 | conversion table. |
| 45 | memory_replay: Only when ``with_decoder=True``. Whether to train the model |
| 46 | with memory replay, so that it predicts all SuperAnimal bodyparts. |
| 47 | customized_pose_checkpoint: A customized SuperAnimal pose checkpoint, as an |
| 48 | alternative to the Hugging Face one |
| 49 | customized_detector_checkpoint: A customized SuperAnimal detector checkpoint, as |
| 50 | an alternative to the Hugging Face one |
| 51 | |
| 52 | To build a WeightInitialization instance for a project using the conversion table |
| 53 | specified in the project configuration file, use: |
| 54 | |
| 55 | ``` |
| 56 | from pathlib import Path |
| 57 | from deeplabcut.utils.auxiliaryfunctions import read_config |
| 58 | from deeplabcut.modelzoo import build_weight_init |
| 59 | |
| 60 | project_cfg = read_config("/path/to/my/project/config.yaml") |
| 61 | super_animal = "superanimal_quadruped" |
| 62 | weight_init = build_weight_init( |
| 63 | cfg=project_cfg, |
| 64 | super_animal="superanimal_quadruped", |
| 65 | model_name="hrnet_w32", |
| 66 | detector_name="fasterrcnn_resnet50_fpn_v2", |
| 67 | with_decoder=True, |
| 68 | memory_replay=False, |
| 69 | ) |
| 70 | ``` |
| 71 | |
| 72 | Returns: |
| 73 | The built WeightInitialization. |
| 74 | """ |
| 75 | if super_animal == "superanimal_humanbody": |
| 76 | raise NotImplementedError( |
| 77 | "Weight Initialization, Transfer-Learning and Finetuning is currently not supported for" |
| 78 | "superanimal_humanbody" |
| 79 | ) |
| 80 |
no test coverage detected