Creates a conversion table mapping bodyparts defined for a DeepLabCut project to bodyparts defined for a SuperAnimal model. This allows to fine-tune SuperAnimal weights instead of transfer learning from ImageNet. The conversion table is directly added to the project's configuration file.
(
config: str | Path,
super_animal: str,
project_to_super_animal: dict[str, str],
)
| 99 | |
| 100 | |
| 101 | def create_conversion_table( |
| 102 | config: str | Path, |
| 103 | super_animal: str, |
| 104 | project_to_super_animal: dict[str, str], |
| 105 | ) -> ConversionTable: |
| 106 | """Creates a conversion table mapping bodyparts defined for a DeepLabCut project to |
| 107 | bodyparts defined for a SuperAnimal model. This allows to fine-tune SuperAnimal |
| 108 | weights instead of transfer learning from ImageNet. The conversion table is directly |
| 109 | added to the project's configuration file. |
| 110 | |
| 111 | Args: |
| 112 | config: The path to the project configuration for which the conversion table |
| 113 | should be created. |
| 114 | super_animal: The SuperAnimal model for the conversion table |
| 115 | project_to_super_animal: The conversion table mapping each project bodypart |
| 116 | to the corresponding SuperAnimal bodypart. |
| 117 | |
| 118 | Returns: |
| 119 | The conversion table that was added to the project config. |
| 120 | |
| 121 | Raises: |
| 122 | ValueError: If the conversion table is misconfigured (e.g., if there are |
| 123 | misnamed bodyparts in the table). See ConversionTable for more. |
| 124 | """ |
| 125 | cfg = read_config(str(config)) |
| 126 | sa_cfg = get_super_animal_project_cfg(super_animal) |
| 127 | conversion_table = ConversionTable( |
| 128 | super_animal=super_animal, |
| 129 | project_bodyparts=get_bodyparts(cfg), |
| 130 | super_animal_bodyparts=sa_cfg["bodyparts"], |
| 131 | table=project_to_super_animal, |
| 132 | ) |
| 133 | |
| 134 | conversion_tables = cfg.get("SuperAnimalConversionTables") |
| 135 | if conversion_tables is None: |
| 136 | conversion_tables = {} |
| 137 | |
| 138 | conversion_tables[super_animal] = conversion_table.table |
| 139 | cfg["SuperAnimalConversionTables"] = conversion_tables |
| 140 | write_config(str(config), cfg) |
| 141 | return conversion_table |
| 142 | |
| 143 | |
| 144 | def get_conversion_table(cfg: dict | str | Path, super_animal: str) -> ConversionTable: |
nothing calls this directly
no test coverage detected