forked from DeepLabCut/DeepLabCut
-
Notifications
You must be signed in to change notification settings - Fork 0
Enhance Checkpoint Management, Debugging, and File Utilities #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
100 commits
Select commit
Hold shift + click to select a range
31d8652
Fix: correct the early return error when save_epochs=1 and delelte th…
xiu-cs 12ed9bd
add plot_gt_and_prediction function
xiu-cs 614b1ac
delete the initial attempt at function
xiu-cs 11c322e
add def visualize_coco_predictions(*)
xiu-cs 598d02b
Fix: correct the early return error when save_epochs=1 and delelte th…
xiu-cs 76e10b4
Update deeplabcut/pose_estimation_pytorch/runners/snapshots.py
xiu-cs 0b64247
Merge branch 'pytorch_dlc' into ti/snapshots
xiu-cs 275fff1
add plot_gt_and_prediction function
xiu-cs 564dbe1
delete the initial attempt at function
xiu-cs 41ff721
add def visualize_coco_predictions(*)
xiu-cs 7f6c8c1
Fix: correct the early return error when save_epochs=1 and delelte th…
xiu-cs b91a3f8
black -> snapshots.py
xiu-cs f670407
black -> snapshots.py
xiu-cs 971f737
Revert "Fix: correct the early return error when save_epochs=1 and de…
xiu-cs b2077ee
isort and black -> evaluate.py
xiu-cs 512547e
update
xiu-cs f02bb36
Update README.md
MMathisLab 3bb5098
Load min_n_links from inference_cfg
segashin 193a243
set min_n_links two locations
segashin ae13531
Benchmarking user guide (#2716)
dikraMasrour 9fb4799
readme link fix
MMathisLab c7f20bd
adding docs for using data labeled elsewhere (formatting) (#2736)
MMathisLab 6f09586
Update standardDeepLabCut_UserGuide.md (#2761)
bendichter 9963a2c
Create citation.md (#2767)
MMathisLab b7a6467
fix tmpdir file creation (#2768)
n-poulsen 41aa1b6
bug fix: None has no lower() attribute (#2780)
n-poulsen ee0e561
Use architecture-specific snapshots prefixes in video adaptation (#2781)
maximpavliv c41a138
Video Analysis with Identity - Lowering memory footprint (#2785)
n-poulsen f2663fb
Timeout retrieving latest package version from the Web (#2782)
maximpavliv 681d968
Fix: correct the early return error when save_epochs=1 and delelte th…
xiu-cs 329402f
add plot_gt_and_prediction function
xiu-cs 6bdf05c
delete the initial attempt at function
xiu-cs a3e99c4
add def visualize_coco_predictions(*)
xiu-cs 1b98090
Revert "Fix: correct the early return error when save_epochs=1 and de…
xiu-cs b0c1fd9
isort and black -> evaluate.py
xiu-cs 94a310d
Load scheduler state when resuming training (#2788)
n-poulsen 5443212
Fix: correct the early return error when save_epochs=1 and delelte th…
xiu-cs 3807963
Update deeplabcut/pose_estimation_pytorch/runners/snapshots.py
xiu-cs 4e7ed49
DeepLabCut 3.0 - Video Analysis with `use_shelve=True` (#2790)
n-poulsen 6128ae2
update
xiu-cs fe9e850
add def visualize_coco_predictions(*)
xiu-cs d6e2a0a
Fix: correct the early return error when save_epochs=1 and delelte th…
xiu-cs 049f7fa
black -> snapshots.py
xiu-cs 56222ed
update
xiu-cs 421af7d
update from coco_ploting
xiu-cs 7369cdc
update
xiu-cs 5611e01
fix the vis for multi-animal
xiu-cs da99c66
add plot_gt_and_prediction function
xiu-cs 2643d6b
delete the initial attempt at function
xiu-cs 3aa926b
add def visualize_coco_predictions(*)
xiu-cs f0a24f7
isort and black -> evaluate.py
xiu-cs 1fdd31e
modify the output_dir
xiu-cs bec1cff
Revert "black -> snapshots.py"
xiu-cs 17fe504
revert changes to snapshots
xiu-cs bf80861
optimize the input params
xiu-cs 694a814
rename the function and fix the multi-animal ploting problem
xiu-cs a731901
use num_individuals
xiu-cs 74e8954
optimize the codes
xiu-cs c4b5a4a
add show_ground_truth param for future use
xiu-cs e33a745
black
xiu-cs c56a1f8
merge ti/coco_plotting to latest
xiu-cs 6110d5b
modify
xiu-cs 80fce45
save bboxes in _full.pickle
maximpavliv f39f03b
Plot bounding boxes in network evaluation
maximpavliv 566aa39
Plot bboxes in create_video_with_all_detections
maximpavliv ec7d643
Plot bounding boxes in create_labeled_video
maximpavliv e5372e6
black
maximpavliv 4017639
rename method
maximpavliv 4e9f48a
add param description
maximpavliv 3eacc3c
fix param default value
maximpavliv 4dfdc10
plot bounding boxes in visualize_predictions
maximpavliv 320a03f
black
maximpavliv 6004ad2
merge maxim/save_plot_bboxes
xiu-cs 3e1251b
add adaptive dot_size to visualize_predictions(*); dot_size is calcul…
xiu-cs 241ea29
add pfm format plotting function: including skeleton, skeleton_name, …
xiu-cs 5d5c9cb
Merge branch 'main' into latest
xiu-cs 3dda8c0
add pfm plotting: skeleton, skeleton_name, masking
xiu-cs 1c6d898
add libraries for evaluation and visualization in PFM predictions
xiu-cs 66f881d
add dynamic skeleton function to make adjustment based on keypoint co…
xiu-cs 05c12c6
add DynamicSkeleton class for improved dynamic skeleton generation ba…
xiu-cs 331e3a4
DynamicSkeleton class: update keypoint names and enhance parent mappi…
xiu-cs 01bbb21
plot_gt_and_predictions_PFM: improve text position tracking to avoid …
xiu-cs 1763f1a
update parent mapping for tail in DynamicSkeleton and refine dot size…
xiu-cs 4c46360
add json_tools module; first function: converting and formatting JSON…
xiu-cs 583d5d9
add download_from_huggingface_hub function
xiu-cs c6e3630
Merge branch 'main' into latest
xiu-cs c5ddbfe
debug
xiu-cs 508e985
Merge branch 'latest' into pfm
xiu-cs 89d33a9
SuperAnimal VideoAdaptation: Fix Checkpoint Inconsistency Error
xiu-cs c64cced
Enhance get_checkpoint_epoch function to handle missing metadata grac…
xiu-cs 634e969
Add import for matplotlib.patches in evaluation.py
xiu-cs 2275cce
Merge branch 'pfm' into latest
xiu-cs bff93af
Update deeplabcut/pose_estimation_pytorch/apis/evaluation.py
xiu-cs 1ddb028
Merge branch 'main' into latest
xiu-cs 090a0aa
Fix typo in find_nearest_ancestor method name in evaluation.py
xiu-cs 3dfa7aa
Update deeplabcut/pose_estimation_pytorch/apis/evaluation.py
xiu-cs e6cdf49
Refactor change_name_to_idx_dynamic_skeleton method in evaluation.py
xiu-cs 9b06f41
Update .circleci/data
xiu-cs 8fcc167
Update deeplabcut/pose_estimation_pytorch/runners/train.py
xiu-cs 29393a6
Refactor change_name_to_idx_dynamic_skeleton method in evaluation.py
xiu-cs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ${DATA_DIR:-./data} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| from huggingface_hub import hf_hub_download | ||
| import os | ||
|
|
||
| def download_from_huggingface_hub(target_folder_path, repo_id, filename, subfolder=None): | ||
| """ | ||
| Download a file from the Hugging Face Hub to a specified local directory. | ||
|
|
||
| Parameters: | ||
| target_folder_path (str): Local directory path where file will be saved | ||
| repo_id (str): Hugging Face repository ID (e.g., 'noahcao/sapiens-pose-coco') | ||
| filename (str): Name of the file to download | ||
| subfolder (str, optional): Path to subfolder within the repository where the file is located | ||
|
|
||
| Returns: | ||
| str: Full path to the downloaded file | ||
|
|
||
| Examples: | ||
| >>> # Download a model file from noahcao/sapiens-pose-coco | ||
| >>> download_from_huggingface_hub( | ||
| ... target_folder_path="./models/sapiens", | ||
| ... repo_id="noahcao/sapiens-pose-coco", | ||
| ... filename="sapiens_2b_coco_best_coco_AP_822_torchscript.pt2", | ||
| ... subfolder="sapiens_lite_host/torchscript/pose/checkpoints/sapiens_2b" | ||
| ... ) | ||
|
|
||
| >>> # Download a file without specifying a subfolder | ||
| >>> download_from_huggingface_hub( | ||
| ... target_folder_path="./data", | ||
| ... repo_id="noahcao/sapiens-pose-coco", | ||
| ... filename="COCO_val2017_detections_AP_H_70_person.json", | ||
| ... subfolder="sapiens_host/pose/person_detection_results" | ||
| ... ) | ||
| """ | ||
| # Create the target directory if it does not exist | ||
| os.makedirs(target_folder_path, exist_ok=True) | ||
|
|
||
| # Download the file from Hugging Face Hub | ||
| return hf_hub_download( | ||
| repo_id=repo_id, | ||
| filename=filename, | ||
| subfolder=subfolder, | ||
| local_dir=target_folder_path | ||
| ) | ||
|
|
||
| # Example usage: | ||
| if __name__ == "__main__": | ||
| # Example to download the model from noahcao/sapiens-pose-coco repository | ||
| target_dir = "xxxx/sapiens/sapiens_lite_host/torchscript/pose/checkpoints/sapiens_2b" | ||
|
|
||
| downloaded_file = download_from_huggingface_hub( | ||
| target_folder_path=target_dir, | ||
| repo_id="noahcao/sapiens-pose-coco", | ||
| filename="sapiens_2b_coco_best_coco_AP_822_torchscript.pt2", | ||
| subfolder="sapiens_lite_host/torchscript/pose/checkpoints/sapiens_2b" | ||
| ) | ||
|
|
||
| print(f"File downloaded to: {downloaded_file}") | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import json | ||
| import os | ||
| from pathlib import Path | ||
|
|
||
| def convert_json_indent_folder_level(source_folder_path, target_folder_path): | ||
| """ | ||
| Read JSON files and save them with proper indentation. | ||
|
|
||
| Args: | ||
| source_folder_path (str): Path to the folder containing original JSON files | ||
| target_folder_path (str): Path to save the formatted JSON files | ||
| """ | ||
| # Create target folder if it doesn't exist | ||
| Path(target_folder_path).mkdir(parents=True, exist_ok=True) | ||
|
|
||
| # Get all JSON files from source folder | ||
| json_files = [f for f in os.listdir(source_folder_path) if f.endswith('.json')] | ||
| print(f"Processing {len(json_files)} JSON files...") | ||
|
|
||
| for json_file in json_files: | ||
| source_path = os.path.join(source_folder_path, json_file) | ||
| target_path = os.path.join(target_folder_path, json_file) | ||
|
|
||
| # Read source JSON file and save with proper indentation | ||
| with open(source_path, 'r') as f: | ||
| data = json.load(f) | ||
|
|
||
| with open(target_path, 'w') as f: | ||
| json.dump(data, f, indent=4) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ | |
|
|
||
| import json | ||
| import os | ||
| import torch | ||
| from pathlib import Path | ||
| from typing import Optional, Union | ||
|
|
||
|
|
@@ -34,6 +35,21 @@ | |
| video_to_frames, | ||
| ) | ||
|
|
||
| def get_checkpoint_epoch(checkpoint_path): | ||
| """ | ||
| Load a PyTorch checkpoint and return the current epoch number. | ||
|
|
||
| Args: | ||
| checkpoint_path (str): Path to the checkpoint file | ||
|
|
||
| Returns: | ||
| int: Current epoch number, or None if not found | ||
| """ | ||
| checkpoint = torch.load(checkpoint_path) | ||
| if 'metadata' in checkpoint and 'epoch' in checkpoint['metadata']: | ||
| return checkpoint['metadata']['epoch'] | ||
| else: | ||
| return 0 | ||
|
|
||
| def get_checkpoint_epoch(checkpoint_path): | ||
|
||
| """ | ||
|
|
@@ -517,7 +533,6 @@ def video_inference_superanimal( | |
|
|
||
| model_snapshot_prefix = f"snapshot-{model_name}" | ||
| detector_snapshot_prefix = f"snapshot-{detector_name}" | ||
|
|
||
| config["runner"]["snapshot_prefix"] = model_snapshot_prefix | ||
| config["detector"]["runner"]["snapshot_prefix"] = detector_snapshot_prefix | ||
|
|
||
|
|
@@ -599,6 +614,7 @@ def video_inference_superanimal( | |
| detector_batch_size=video_adapt_batch_size, | ||
| ) | ||
|
|
||
|
|
||
| # after video adaptation, re-update the adapted checkpoint path, if the checkpoint does not exist, use the best checkpoint | ||
| adapted_detector_checkpoint = ( | ||
| model_folder | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function
get_checkpoint_epochis defined twice in the same file (lines 38 and 54). This will cause the second definition to override the first one, making the first implementation unreachable.