Skip to content

fix/update: corrected torch.py and added testing suite for utility functions#519

Open
kashtennyson wants to merge 5 commits into
JdeRobot:masterfrom
kashtennyson:issue-518
Open

fix/update: corrected torch.py and added testing suite for utility functions#519
kashtennyson wants to merge 5 commits into
JdeRobot:masterfrom
kashtennyson:issue-518

Conversation

@kashtennyson

@kashtennyson kashtennyson commented Mar 27, 2026

Copy link
Copy Markdown
Contributor

Overview
This PR fixes a bug in the torch utility function and introduces a comprehensive unit testing suite for torch.py and image.py. This is a fix for #518

Changes

  • utils/torch.py Fix:
    • Updated get_data_shape() to implement "passthrough" logic for non-tensor base cases (e.g., strings, labels, or None).
    • This prevents AttributeError when this function encounters metadata bundled with tensors.
  • New Unit Tests:
    • tests/test_torch.py: Validates recursive operations on complex, nested, and mixed-type data structures.
    • tests/test_image.py: Verifies visualization helpers, including label formatting and annotator calls, using a robust mocking strategy.

Verification
The new test modules pass successfully:

poetry run pytest tests/test_torch.py tests/test_image.py

Results: 7 passed in 1.71s (4 in torch, 3 in image).

@dpascualhe dpascualhe left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Besides the pending comment, can you rename the test files to something like test_utils_image.py and test_utils_torch? Thanks!

Comment thread perceptionmetrics/utils/torch.py Outdated
@kashtennyson

Copy link
Copy Markdown
Contributor Author

Renaming the test files to test_utils_torch.py and test_utils_image.py will break the naming consistency with the rest of the utility test scripts (e.g., test_conversion.py, test_io.py). Instead, I suggest organizing all utility test scripts under a new tests/utils/ directory. This will mirror the source structure while keeping the filenames clean and consistent. Please let me know your preference for this. Thanks!

@kashtennyson

Copy link
Copy Markdown
Contributor Author

Hey @dpascualhe, still waiting on this PR's status and your preference on my suggestions in the previous comment. Thanks!

@dpascualhe

Copy link
Copy Markdown
Collaborator

Hi @kashtennyson , I like that suggestion! could you rename all test modules so that they mirror the directory structure within perceptionmetrics?

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.

2 participants