| 340 | |
| 341 | |
| 342 | def run( |
| 343 | config_path: Path, |
| 344 | train_fraction: float, |
| 345 | trainset_index: int, |
| 346 | net_type: str, |
| 347 | videos: list[str], |
| 348 | device: str, |
| 349 | engine: Engine = Engine.PYTORCH, |
| 350 | pytorch_cfg_updates: dict | None = None, |
| 351 | create_labeled_videos: bool = False, |
| 352 | ) -> None: |
| 353 | times = [time.time()] |
| 354 | log_step(f"Testing with net type {net_type}") |
| 355 | log_step("Creating the training dataset") |
| 356 | deeplabcut.create_training_dataset(str(config_path), net_type=net_type, engine=engine) |
| 357 | existing_shuffles = get_existing_shuffle_indices(config_path, train_fraction=train_fraction, engine=engine) |
| 358 | shuffle_index = existing_shuffles[-1] |
| 359 | |
| 360 | log_step(f"Starting training for train_frac {train_fraction}, shuffle {shuffle_index}") |
| 361 | deeplabcut.train_network( |
| 362 | config=str(config_path), |
| 363 | shuffle=shuffle_index, |
| 364 | trainingsetindex=trainset_index, |
| 365 | device=device, |
| 366 | pytorch_cfg_updates=pytorch_cfg_updates, |
| 367 | ) |
| 368 | times.append(time.time()) |
| 369 | log_step(f"Train time: {times[-1] - times[-2]} seconds") |
| 370 | |
| 371 | log_step(f"Starting evaluation for train_frac {train_fraction}, shuffle {shuffle_index}") |
| 372 | deeplabcut.evaluate_network( |
| 373 | config=str(config_path), |
| 374 | Shuffles=[shuffle_index], |
| 375 | trainingsetindex=trainset_index, |
| 376 | device=device, |
| 377 | plotting=True, |
| 378 | per_keypoint_evaluation=True, |
| 379 | ) |
| 380 | times.append(time.time()) |
| 381 | log_step(f"Evaluation time: {times[-1] - times[-2]} seconds") |
| 382 | |
| 383 | if len(videos) > 0: |
| 384 | log_step(f"Analyzing videos for {train_fraction}, shuffle {shuffle_index}") |
| 385 | video_kwargs = dict(videos=videos, shuffle=shuffle_index, trainingsetindex=trainset_index) |
| 386 | deeplabcut.analyze_videos(str(config_path), **video_kwargs, device=device, auto_track=False) |
| 387 | times.append(time.time()) |
| 388 | log_step(f"Video analysis time: {times[-1] - times[-2]} seconds") |
| 389 | log_step(f"Total test time: {times[-1] - times[0]} seconds") |
| 390 | |
| 391 | cfg = af.read_config(config_path) |
| 392 | if cfg.get("multianimalproject"): |
| 393 | if create_labeled_videos: |
| 394 | deeplabcut.create_video_with_all_detections(str(config_path), **video_kwargs) |
| 395 | |
| 396 | # relaxed tracking parameters |
| 397 | deeplabcut.convert_detections2tracklets( |
| 398 | str(config_path), |
| 399 | **video_kwargs, |