Runs the keypoint matching algorithm for a DeepLabCut project. Matches project keypoints to SuperAnimal keypoints automatically, by running SuperAnimal inference on all images in the dataset Args: config_path: The path of the DeepLabCut project configuration file. super
(
config_path: str | Path,
superanimal_name: str,
model_name: str,
detector_name: str,
copy_images: bool = False,
device: str | None = None,
train_file: str = "train.json",
)
| 142 | |
| 143 | |
| 144 | def keypoint_matching( |
| 145 | config_path: str | Path, |
| 146 | superanimal_name: str, |
| 147 | model_name: str, |
| 148 | detector_name: str, |
| 149 | copy_images: bool = False, |
| 150 | device: str | None = None, |
| 151 | train_file: str = "train.json", |
| 152 | ): |
| 153 | """Runs the keypoint matching algorithm for a DeepLabCut project. |
| 154 | |
| 155 | Matches project keypoints to SuperAnimal keypoints automatically, by running |
| 156 | SuperAnimal inference on all images in the dataset |
| 157 | |
| 158 | Args: |
| 159 | config_path: The path of the DeepLabCut project configuration file. |
| 160 | superanimal_name: SuperAnimal dataset with which to run keypoint matching. |
| 161 | model_name: Name of the SuperAnimal pose model architecture with which to run |
| 162 | keypoint matching |
| 163 | detector_name: Name of the SuperAnimal detector architecture with which to run |
| 164 | keypoint matching |
| 165 | copy_images: When False, symlinks are created for the dataset used for keypoint |
| 166 | matching. Otherwise, images are copied from the `labeled-data` folder to the |
| 167 | folder used for keypoint matching. |
| 168 | device: The device on which to run keypoint matching. |
| 169 | train_file: The name of the file containing the labels to output. |
| 170 | """ |
| 171 | config_path = Path(config_path) |
| 172 | cfg = af.read_config(str(config_path)) |
| 173 | dlc_proj_root = config_path.parent |
| 174 | |
| 175 | if "individuals" in cfg: |
| 176 | temp_dataset = MaDLCDataFrame(str(dlc_proj_root), "temp_dataset") |
| 177 | max_individuals = len(cfg["individuals"]) |
| 178 | else: |
| 179 | temp_dataset = SingleDLCDataFrame(str(dlc_proj_root), "temp_dataset") |
| 180 | max_individuals = 1 |
| 181 | |
| 182 | memory_replay_folder = dlc_proj_root / "memory_replay" |
| 183 | temp_dataset.materialize(str(memory_replay_folder), framework="coco", deepcopy=copy_images) |
| 184 | |
| 185 | # run inference on the train set |
| 186 | config = modelzoo.load_super_animal_config( |
| 187 | super_animal=superanimal_name, |
| 188 | model_name=model_name, |
| 189 | detector_name=detector_name, |
| 190 | ) |
| 191 | if device is None: |
| 192 | device = select_device() |
| 193 | |
| 194 | # get the SuperAnimal detector and pose model snapshot paths |
| 195 | pose_model_path = modelzoo.get_super_animal_snapshot_path( |
| 196 | dataset=superanimal_name, |
| 197 | model_name=model_name, |
| 198 | ) |
| 199 | detector_path = modelzoo.get_super_animal_snapshot_path( |
| 200 | dataset=superanimal_name, |
| 201 | model_name=detector_name, |
nothing calls this directly
no test coverage detected