Skip to content
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

Add feature to evaluate network for specfic, named snapshots. #2508

Merged
merged 30 commits into from
Jul 5, 2024

Conversation

Tetra-quark
Copy link
Contributor

@Tetra-quark Tetra-quark commented Feb 5, 2024

Adds a feature to pass a list of snapshot names snapshots_to_evaluate to the evaluate_network function as an alternative to using the snapshotindex parameter in the main config.yaml file.

The new parameter allows multiple, explicitly named snapshots to be evaluated where previously only a single snapshot or "all" could be chosen.

This pull request closes #2356.

Overview of changes:

  • Add snapshots_to_evaluate parameter to both single and multi-animal evaluation.
  • Function get_available_requested_snapshots to handle the snapshots_to_evaluate parameter.
  • Function get_snapshots_by_index to refactor existing snapshotindex from config file functionality.
  • Function get_snapshots_from_folder to refactor getting an ordered list of snapshots from the train folder.
  • Docstring for new functions and parameters.
  • Unit tests for all three new functions.
  • Update testscript.py to use snapshots_to_evaluate in evaluate_network (however in doing so I have disabled the snapshotindex method, both should be in the test ideally).
  • General refactoring, renaming and cleaning.

Example usage:

deeplabcut.evaluate_network(
    config_path, 
    snapshots_to_evaluate=["snapshot-50000", "snapshot-100000"],
)

Tetra-quark and others added 26 commits October 19, 2023 16:30
…isting functionality.

- Replace snapindex with more explicit snapshot_name. snapshotindex from config is used to identify the snapshot name instead.
- Refactor logic for snapshotindex allowed values. Add limit to negative index values.
- Replace snapshots_to_evaluate numpy indexing with list loop
- Raise error if no snapshots are found
# Conflicts:
#	deeplabcut/pose_estimation_tensorflow/core/evaluate.py
* Improve snapshots_to_evaluate docstring
* Get training_iterations from snapshot_name
* Rename trainingsiterations -> training_iterations
* Create get_available_requested_snapshots for obtaining specified snapshot names (new feature).
* Create get_snapshots_by_index to handle the original implementation.
* Minor improvements and fixes
* Add snapshots_to_evaluate parameter to multi-animal evaluation
* Minor renaming
* add evaluate_by_snapshot branch for testing purposes
* Better typehint for int or str
* Raise IndexError instead of ValueError
* Add list_sorted_existing_snapshots to auxiliaryfunctions.py.
* Update several files to use the newly refactored function.
* Preserve same exception handling, albeit with modified message to be more general and concise.
* Add new snapshot auxiliary function usage.
* Preserve continuation of loop if no snapshots are found.
* Update name for all usages
* Minor change to function docstring
* Remove redundant sorting in evaluate_multianimal.py
* Test snapshots present and returned in order
* Test snapshots not found
@Tetra-quark Tetra-quark changed the title Evaluate Network for specfic, named snapshots. Closes DeepLabCut/DeepLabCut#2356 Evaluate network for specfic, named snapshots. Feb 6, 2024
@Tetra-quark Tetra-quark changed the title Evaluate network for specfic, named snapshots. Add feature to evaluate network for specfic, named snapshots. Feb 6, 2024
@MMathisLab MMathisLab added the enhancement New feature or request label Feb 8, 2024
@MMathisLab MMathisLab requested a review from AlexEMG April 27, 2024 09:51
@MMathisLab
Copy link
Member

@n-poulsen and @jeylau let's prioritize this -- I think it's a great addition, and can be worked into DLC3.0

Copy link
Collaborator

@n-poulsen n-poulsen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made some minor linting changes, tested on single + multi-animal projects. Looks good to me (as soon as tests pass)!

Great PR, thanks @Tetra-quark!

@MMathisLab MMathisLab merged commit 6277d77 into DeepLabCut:main Jul 5, 2024
4 checks passed
MMathisLab added a commit that referenced this pull request Jul 16, 2024
* Add feature to evaluate network for specfic, named snapshots. (#2508)

* Add snapshot selection option to evaluate_network while preserving existing functionality.
- Replace snapindex with more explicit snapshot_name. snapshotindex from config is used to identify the snapshot name instead.
- Refactor logic for snapshotindex allowed values. Add limit to negative index values.

* Update evaluate.py
- Replace snapshots_to_evaluate numpy indexing with list loop
- Raise error if no snapshots are found

* Add snapshots_to_evaluate docstring

* Remove unused distance function

* Update evaluate.py
* Improve snapshots_to_evaluate docstring
* Get training_iterations from snapshot_name
* Rename trainingsiterations -> training_iterations

* Improve snapshot_to_evaluate typehint and docstring.

* Refactor evaluate.py
* Create get_available_requested_snapshots for obtaining specified snapshot names (new feature).
* Create get_snapshots_by_index to handle the original implementation.
* Minor improvements and fixes

* Add tests for new snapshot functions in evaluate.py

* Update evaluate_multianimal.py
* Add snapshots_to_evaluate parameter to multi-animal evaluation
* Minor renaming

* Update python-package.yml

* add evaluate_by_snapshot branch for testing purposes

* Add snapshots_to_evaluate usage in testscript.py

* Update get_snapshots_by_index function
* Better typehint for int or str
* Raise IndexError instead of ValueError

* Add get_snapshots_by_index tests to test_evaluate.py

* Update return_evaluate_network_data function with get_snapshots_by_index usage

* Fix potential reference before assignment by raising ValueError

* Refactor getting existing snapshot file names as sorted list.
* Add list_sorted_existing_snapshots to auxiliaryfunctions.py.
* Update several files to use the newly refactored function.
* Preserve same exception handling, albeit with modified message to be more general and concise.

* Refactor evaluate_multianimal.py
* Add new snapshot auxiliary function usage.
* Preserve continuation of loop if no snapshots are found.

* Remove indentation level.

* Rename list_sorted_exisiting_snapshots -> get_snapshots_in_folder
* Update name for all usages
* Minor change to function docstring
* Remove redundant sorting in evaluate_multianimal.py

* Port numpy array to list (not performance critical)

* Add get_snapshots_from_folder tests
* Test snapshots present and returned in order
* Test snapshots not found

* Fix deprecated function names

* Improve snapshots_to_evaluate test in testscript.py

* Correct spelling

* Add per_keypoint_evaluation to evaluate_multianimal_full function call (woops!)

* minor linting

---------

Co-authored-by: Mackenzie Mathis <mathis@rowland.harvard.edu>
Co-authored-by: Niels Poulsen <niels.poulsen@epfl.ch>

* fixed file dialog not showing uppercase file extension video files (#2645)

* fixed file dialog not showing uppercase file extension video files

* bug fix: no shuffle_change slot in main window

* bug fix

---------

Co-authored-by: Niels Poulsen <niels.poulsen@epfl.ch>
Co-authored-by: Mackenzie Mathis <mathis@rowland.harvard.edu>

---------

Co-authored-by: jkopp <32641315+Tetra-quark@users.noreply.github.com>
Co-authored-by: Mackenzie Mathis <mathis@rowland.harvard.edu>
Co-authored-by: Terry Park <58895710+park-jsdev@users.noreply.github.com>
MMathisLab added a commit that referenced this pull request Jul 19, 2024
* Add feature to evaluate network for specfic, named snapshots. (#2508)

* Add snapshot selection option to evaluate_network while preserving existing functionality.
- Replace snapindex with more explicit snapshot_name. snapshotindex from config is used to identify the snapshot name instead.
- Refactor logic for snapshotindex allowed values. Add limit to negative index values.

* Update evaluate.py
- Replace snapshots_to_evaluate numpy indexing with list loop
- Raise error if no snapshots are found

* Add snapshots_to_evaluate docstring

* Remove unused distance function

* Update evaluate.py
* Improve snapshots_to_evaluate docstring
* Get training_iterations from snapshot_name
* Rename trainingsiterations -> training_iterations

* Improve snapshot_to_evaluate typehint and docstring.

* Refactor evaluate.py
* Create get_available_requested_snapshots for obtaining specified snapshot names (new feature).
* Create get_snapshots_by_index to handle the original implementation.
* Minor improvements and fixes

* Add tests for new snapshot functions in evaluate.py

* Update evaluate_multianimal.py
* Add snapshots_to_evaluate parameter to multi-animal evaluation
* Minor renaming

* Update python-package.yml

* add evaluate_by_snapshot branch for testing purposes

* Add snapshots_to_evaluate usage in testscript.py

* Update get_snapshots_by_index function
* Better typehint for int or str
* Raise IndexError instead of ValueError

* Add get_snapshots_by_index tests to test_evaluate.py

* Update return_evaluate_network_data function with get_snapshots_by_index usage

* Fix potential reference before assignment by raising ValueError

* Refactor getting existing snapshot file names as sorted list.
* Add list_sorted_existing_snapshots to auxiliaryfunctions.py.
* Update several files to use the newly refactored function.
* Preserve same exception handling, albeit with modified message to be more general and concise.

* Refactor evaluate_multianimal.py
* Add new snapshot auxiliary function usage.
* Preserve continuation of loop if no snapshots are found.

* Remove indentation level.

* Rename list_sorted_exisiting_snapshots -> get_snapshots_in_folder
* Update name for all usages
* Minor change to function docstring
* Remove redundant sorting in evaluate_multianimal.py

* Port numpy array to list (not performance critical)

* Add get_snapshots_from_folder tests
* Test snapshots present and returned in order
* Test snapshots not found

* Fix deprecated function names

* Improve snapshots_to_evaluate test in testscript.py

* Correct spelling

* Add per_keypoint_evaluation to evaluate_multianimal_full function call (woops!)

* minor linting

---------

Co-authored-by: Mackenzie Mathis <mathis@rowland.harvard.edu>
Co-authored-by: Niels Poulsen <niels.poulsen@epfl.ch>

* fixed file dialog not showing uppercase file extension video files (#2645)

* fixed file dialog not showing uppercase file extension video files

* bug fix: no shuffle_change slot in main window

* bug fix

---------

Co-authored-by: Niels Poulsen <niels.poulsen@epfl.ch>
Co-authored-by: Mackenzie Mathis <mathis@rowland.harvard.edu>

---------

Co-authored-by: jkopp <32641315+Tetra-quark@users.noreply.github.com>
Co-authored-by: Mackenzie Mathis <mathis@rowland.harvard.edu>
Co-authored-by: Terry Park <58895710+park-jsdev@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request high-priority
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Request snapshot number parameter in evaluate_network() as alternative to snapshotindex.
3 participants