-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Set weights_only=True as a default when loading snapshot weights.
#2818
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
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
286d8e5
set weights_only parameter when loading model weights
n-poulsen 57a8119
isort + black
n-poulsen c0812c2
remove unused import
n-poulsen 2a2c678
connect to build_inference_runner calls
n-poulsen 362ce99
fix edited file
n-poulsen 2a71bdf
fix edited file
n-poulsen 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
Next
Next commit
set weights_only parameter when loading model weights
- Loading branch information
commit 286d8e5827eea152ff8212e113ef70f13de238e5
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
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
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
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
31 changes: 31 additions & 0 deletions
31
tests/pose_estimation_pytorch/modelzoo/test_load_superanimal_models.py
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,31 @@ | ||
| # | ||
| # DeepLabCut Toolbox (deeplabcut.org) | ||
| # © A. & M.W. Mathis Labs | ||
| # https://github.com/DeepLabCut/DeepLabCut | ||
| # | ||
| # Please see AUTHORS for contributors. | ||
| # https://github.com/DeepLabCut/DeepLabCut/blob/main/AUTHORS | ||
| # | ||
| # Licensed under GNU Lesser General Public License v3.0 | ||
| # | ||
| import dlclibrary | ||
| import pytest | ||
| import torch | ||
|
|
||
| from deeplabcut.pose_estimation_pytorch.modelzoo import get_super_animal_snapshot_path | ||
|
|
||
|
|
||
| @pytest.mark.skip(reason="require-models") | ||
| def test_load_superanimal_models_weights_only(): | ||
| super_animal_names = dlclibrary.get_available_datasets() | ||
| for super_animal in super_animal_names: | ||
| print(f"\nTesting {super_animal}") | ||
| for detector in dlclibrary.get_available_detectors(super_animal): | ||
| print(super_animal, detector) | ||
| path = get_super_animal_snapshot_path(super_animal, detector) | ||
| snapshot = torch.load(path, map_location="cpu", weights_only=True) | ||
|
|
||
| for pose_model in dlclibrary.get_available_models(super_animal): | ||
| print(super_animal, pose_model) | ||
| path = get_super_animal_snapshot_path(super_animal, pose_model) | ||
| snapshot = torch.load(path, map_location="cpu", weights_only=True) | ||
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 @@ | ||
| # | ||
| # DeepLabCut Toolbox (deeplabcut.org) | ||
| # © A. & M.W. Mathis Labs | ||
| # https://github.com/DeepLabCut/DeepLabCut | ||
| # | ||
| # Please see AUTHORS for contributors. | ||
| # https://github.com/DeepLabCut/DeepLabCut/blob/main/AUTHORS | ||
| # | ||
| # Licensed under GNU Lesser General Public License v3.0 | ||
| # | ||
| import pickle | ||
| from unittest.mock import Mock | ||
|
|
||
| import numpy as np | ||
| import pytest | ||
| import torch | ||
|
|
||
| import deeplabcut.pose_estimation_pytorch.runners as runners | ||
|
|
||
|
|
||
| def test_load_snapshot_weights_only_error(tmpdir_factory): | ||
| snapshot_dir = tmpdir_factory.mktemp("snapshot-dir") | ||
| snapshot_path = snapshot_dir / "snapshot.pt" | ||
| torch.save(dict(content=np.zeros(10)), snapshot_path) | ||
|
|
||
| with pytest.raises(pickle.UnpicklingError): | ||
| runners.Runner.load_snapshot( | ||
| snapshot_path, device="cpu", model=Mock(), weights_only=True | ||
| ) |
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.