Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR bumps the version to "3.0.0rc10" and improves error handling and robustness in snapshot and detector snapshot loading while adding messaging for .h5 file generation during video analysis.
- Updated version strings in setup.py, reinstall.sh, and deeplabcut/version.py.
- Enhanced snapshot extraction using regex in snapshots.py to better handle filename edge cases.
- Added try/except blocks and fallback logic in videos.py (and minor messaging improvements in evaluation.py) to ensure graceful recovery when snapshots are missing.
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| setup.py | Updated version to rc10. |
| reinstall.sh | Updated version in install command. |
| deeplabcut/version.py | Updated internal version string to rc10. |
| deeplabcut/pose_estimation_pytorch/data/snapshots.py | Enhanced snapshot epoch extraction with regex and fallback logic. |
| deeplabcut/pose_estimation_pytorch/apis/videos.py | Added robust error handling and alternative snapshot search with user messages. |
| deeplabcut/pose_estimation_pytorch/apis/evaluation.py | Added print statements to display evaluation results information. |
Comments suppressed due to low confidence (1)
deeplabcut/pose_estimation_pytorch/data/snapshots.py:41
- The regex pattern for extracting epoch numbers is a robust improvement; please verify that it correctly handles all expected snapshot filename formats.
match = re.search(r'-(\d+)\.pt$', path.name)
| try: | ||
| snapshot = utils.get_model_snapshots( | ||
| snapshot_index, loader.model_folder, loader.pose_task | ||
| )[0] | ||
| except (ValueError, IndexError) as e: | ||
| print(f"Error loading snapshot with index {snapshot_index}: {e}") | ||
| print("Attempting to find available snapshots...") | ||
|
|
||
| # Try to get all available snapshots | ||
| try: | ||
| all_snapshots = utils.get_model_snapshots("all", loader.model_folder, loader.pose_task) | ||
| if all_snapshots: | ||
| # Try to find a "best" snapshot first | ||
| best_snapshots = [s for s in all_snapshots if s.best] | ||
| if best_snapshots: | ||
| snapshot = best_snapshots[0] | ||
| print(f"Found and using best snapshot: {snapshot.path}") | ||
| else: | ||
| # Use the last available snapshot | ||
| snapshot = all_snapshots[-1] | ||
| print(f"No best snapshot found, using last available: {snapshot.path}") | ||
| else: | ||
| raise FileNotFoundError(f"No snapshots found in {loader.model_folder}") | ||
| except Exception as fallback_error: | ||
| raise FileNotFoundError(f"Failed to load any snapshots from {loader.model_folder}. Original error: {e}. Fallback error: {fallback_error}") |
There was a problem hiding this comment.
[nitpick] Consider refactoring the repeated error handling logic for loading snapshots into a helper function to reduce code duplication and improve maintainability.
| try: | |
| snapshot = utils.get_model_snapshots( | |
| snapshot_index, loader.model_folder, loader.pose_task | |
| )[0] | |
| except (ValueError, IndexError) as e: | |
| print(f"Error loading snapshot with index {snapshot_index}: {e}") | |
| print("Attempting to find available snapshots...") | |
| # Try to get all available snapshots | |
| try: | |
| all_snapshots = utils.get_model_snapshots("all", loader.model_folder, loader.pose_task) | |
| if all_snapshots: | |
| # Try to find a "best" snapshot first | |
| best_snapshots = [s for s in all_snapshots if s.best] | |
| if best_snapshots: | |
| snapshot = best_snapshots[0] | |
| print(f"Found and using best snapshot: {snapshot.path}") | |
| else: | |
| # Use the last available snapshot | |
| snapshot = all_snapshots[-1] | |
| print(f"No best snapshot found, using last available: {snapshot.path}") | |
| else: | |
| raise FileNotFoundError(f"No snapshots found in {loader.model_folder}") | |
| except Exception as fallback_error: | |
| raise FileNotFoundError(f"Failed to load any snapshots from {loader.model_folder}. Original error: {e}. Fallback error: {fallback_error}") | |
| snapshot = load_snapshot_with_fallback( | |
| snapshot_index, loader.model_folder, loader.pose_task | |
| ) |
| print(f"Error loading snapshot with index {snapshot_index}: {e}") | ||
| print("Attempting to find available snapshots...") |
There was a problem hiding this comment.
[nitpick] Using print statements for error reporting may limit flexibility; consider using a logging framework that allows configurable log levels and better integration in production.
| print(f"Error loading snapshot with index {snapshot_index}: {e}") | |
| print("Attempting to find available snapshots...") | |
| logging.error(f"Error loading snapshot with index {snapshot_index}: {e}") | |
| logging.info("Attempting to find available snapshots...") |
| detector_snapshot = utils.get_model_snapshots( | ||
| detector_snapshot_index, loader.model_folder, Task.DETECT | ||
| )[0] | ||
| try: |
There was a problem hiding this comment.
[nitpick] The error handling logic for detector snapshot loading is almost identical to that for the model snapshot; consider abstracting this logic into a shared function to reduce duplication.
| ) | ||
| scores_filepath = output_filename.with_suffix(".csv") | ||
| scores_filepath = scores_filepath.with_stem(scores_filepath.stem + "-results") | ||
| print(f"Evaluation results file: {scores_filepath.name}") |
There was a problem hiding this comment.
[nitpick] Consider replacing print statements with a logging framework to allow for configurable and consistent output handling across the codebase.
| print(f"Evaluation results file: {scores_filepath.name}") | |
| logging.info(f"Evaluation results file: {scores_filepath.name}") |
| snapshot_uid=get_scorer_uid(snapshot, detector_snapshot), | ||
| modelprefix=modelprefix, | ||
| ) | ||
| print(f"Evaluation scorer: {scorer}") |
There was a problem hiding this comment.
[nitpick] Consider using logging here instead of print to ensure consistency with other parts of the code that handle error and info messages.
No description provided.