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 torchvision.transforms v1/v2 independent ToTensor() implementation #1718

Merged
merged 7 commits into from
Nov 6, 2024

Conversation

liopeer
Copy link
Contributor

@liopeer liopeer commented Nov 6, 2024

Changes

  • add ToTensor() transform that is independent of the imported torchvision.transforms version (v1 or v2)
  • make it available for import from the lightly.transforms module
  • add testing of output tensor:
    • correct dtype (from np.uint8 to torch.float32)
    • correct shape (from channel last to channel first)
    • value range: from [0, 255] to [0, 1]

Copy link

codecov bot commented Nov 6, 2024

Codecov Report

Attention: Patch coverage is 76.47059% with 4 lines in your changes missing coverage. Please review.

Project coverage is 84.88%. Comparing base (c22ee83) to head (d820430).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
lightly/transforms/torchvision_v2_compatibility.py 75.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1718      +/-   ##
==========================================
- Coverage   84.88%   84.88%   -0.01%     
==========================================
  Files         157      157              
  Lines        6537     6543       +6     
==========================================
+ Hits         5549     5554       +5     
- Misses        988      989       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@liopeer liopeer enabled auto-merge (squash) November 6, 2024 09:18
tests/transforms/test_torchvision_transforms.py Outdated Show resolved Hide resolved
lightly/transforms/torchvision_transforms.py Outdated Show resolved Hide resolved
@liopeer
Copy link
Contributor Author

liopeer commented Nov 6, 2024

Additional Changes

  • removed assertion statements & imported class directly as requested
  • added missing docstring to the transform (tried to stay close to the docstrings of other transforms)
  • renamed the module in which the transform resides to torchvision_v2compatibility to resolve name-space issues

Copy link
Contributor

@guarin guarin left a comment

Choose a reason for hiding this comment

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

LGTM! Feel free to resolve and merge my comment.

lightly/transforms/torchvision_v2compatibility.py Outdated Show resolved Hide resolved
@liopeer liopeer merged commit 01fdac4 into master Nov 6, 2024
13 of 14 checks passed
@liopeer liopeer deleted the lionel-lig-5622-add-totensor-v2-transform branch November 6, 2024 14:30
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