-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Added Histogram Transformation #796
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
base: main
Are you sure you want to change the base?
Conversation
As I have discussed in a feature request (link1), HistogramTransformation is very useful, especially when handling raw data in photography or astronomy. Please see the following gits (link2) for its functionality, examples, and proof of concept. link1: pytorch#598 link2: https://gist.github.com/Miladiouss/86bed5c53595116dfe18ee0a5c84f838
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As requested in #598 except for np.interp
all the other usage of numpy as can be replace by a torch equivalent.
torchvision/transforms/transforms.py
Outdated
tensor = tensor.ravel() | ||
|
||
# Get counts, bins, and corresponding bin indices for each tensor value | ||
counts, bins = np.histogram(tensor, bins = t_bins) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you change this to torch equivalent torch.histc()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately not; mainly because np.histogram accepts variable bin interval while torch.histc can only handle equal bin interval. Also, that would require conversion between np.array and torch.tensor multiple times.
Codecov Report
@@ Coverage Diff @@
## master #796 +/- ##
=========================================
Coverage ? 37.86%
=========================================
Files ? 32
Lines ? 3159
Branches ? 490
=========================================
Hits ? 1196
Misses ? 1884
Partials ? 79
Continue to review full report at Codecov.
|
I used a code beautifier to get rid of spacing errors raised by flake8.
I am not familiar with codecov. Can someone please help me pass the checks? |
@Miladiouss You should also add test code in test/test_transforms.py. You can find examples at this file. |
As I have discussed in a feature request, HistogramTransformation is very useful, especially when handling raw data in photography or astronomy. Please see this gist for its functionality, examples, tests, and proof of concept.