FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

edge case fix / rc10 by MMathisLab · Pull Request #3036 · DeepLabCut/DeepLabCut · GitHub

edge case fix / rc10 - #3036

Merged
AlexEMG merged 4 commits into
mainfrom
mwm/video
Jul 1, 2025
Merged

edge case fix / rc10#3036
AlexEMG merged 4 commits into
mainfrom
mwm/video

Conversation

Copy link
Copy Markdown
Member

No description provided.

MMathisLab requested a review from Copilot July 1, 2025 03:30

This comment was marked as outdated.

MMathisLab changed the title edge case fix edge case fix / rc10 Jul 1, 2025
MMathisLab requested review from AlexEMG and Copilot July 1, 2025 03:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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)

Comment on lines +452 to +476
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}")

Copilot AI Jul 1, 2025

Copy link

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

[nitpick] Consider refactoring the repeated error handling logic for loading snapshots into a helper function to reduce code duplication and improve maintainability.

Suggested change
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
)

Copilot uses AI. Check for mistakes.
Comment on lines +457 to +458
print(f"Error loading snapshot with index {snapshot_index}: {e}")
print("Attempting to find available snapshots...")

Copilot AI Jul 1, 2025

Copy link

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

[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.

Suggested change
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...")

Copilot uses AI. Check for mistakes.
detector_snapshot = utils.get_model_snapshots(
detector_snapshot_index, loader.model_folder, Task.DETECT
)[0]
try:

Copilot AI Jul 1, 2025

Copy link

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

[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.

Copilot uses AI. Check for mistakes.
)
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}")

Copilot AI Jul 1, 2025

Copy link

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

[nitpick] Consider replacing print statements with a logging framework to allow for configurable and consistent output handling across the codebase.

Suggested change
print(f"Evaluation results file: {scores_filepath.name}")
logging.info(f"Evaluation results file: {scores_filepath.name}")

Copilot uses AI. Check for mistakes.
snapshot_uid=get_scorer_uid(snapshot, detector_snapshot),
modelprefix=modelprefix,
)
print(f"Evaluation scorer: {scorer}")

Copilot AI Jul 1, 2025

Copy link

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

[nitpick] Consider using logging here instead of print to ensure consistency with other parts of the code that handle error and info messages.

Copilot uses AI. Check for mistakes.
AlexEMG merged commit d11f093 into main Jul 1, 2025
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants


Back | FazBrowse Home | New Git URL