question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug] RandomEqualize() function seems wrong

See original GitHub issue

🐛 Bug

When I use the kornia.augmentation.RandomEqualize() (or kornia.enhance.adjust.equalize()), I’m not seeing any change in the input. When I use a similar function in opencv, I see a different output. Am I missing something?

To Reproduce

Steps to reproduce the behavior:

>>> rng = torch.manual_seed(0)
>>> arr = 0.5*torch.rand(5,5) + 0.25
>>> print(arr)
tensor([[0.4981, 0.6341, 0.2942, 0.3160, 0.4037],
        [0.5670, 0.4950, 0.6982, 0.4778, 0.5662],
        [0.4244, 0.4509, 0.2612, 0.3344, 0.3969],
        [0.5093, 0.5988, 0.6500, 0.3305, 0.3911],
        [0.5908, 0.7076, 0.4485, 0.6871, 0.4597]])
>>> out = kornia.augmentation.RandomEqualize(p=1.)(arr)
>>> print(out)
tensor([[[[0.4981, 0.6341, 0.2942, 0.3160, 0.4037],
          [0.5670, 0.4950, 0.6982, 0.4778, 0.5662],
          [0.4244, 0.4509, 0.2612, 0.3344, 0.3969],
          [0.5093, 0.5988, 0.6500, 0.3305, 0.3911],
          [0.5908, 0.7076, 0.4485, 0.6871, 0.4597]]]])

Expected behavior

I am expecting the resulting matrix to be renormalized in the [0,1] range, since the function definition recommends my input to be in this range as described here: https://github.com/kornia/kornia/blob/master/kornia/augmentation/augmentation.py#L1119

Also, maybe this function should have a min and max equalization range?

>>> import cv2
>>> cv_arr = (arr.cpu().data.numpy())
>>> cv_arr = (cv_arr * 255.).astype(np.uint8)
>>> cv_out = cv2.equalizeHist(cv_arr)
>>> cv_out = (cv_out / 255.).astype(np.float32)
>>> print(torch.from_numpy(cv_out))
tensor([[0.5843, 0.8314, 0.0431, 0.0824, 0.2902],
        [0.7098, 0.5412, 0.9569, 0.5020, 0.7098],
        [0.3333, 0.4157, 0.0000, 0.1647, 0.2510],
        [0.6235, 0.7922, 0.8745, 0.1255, 0.2078],
        [0.7490, 1.0000, 0.4157, 0.9176, 0.4588]])

Environment

Collecting environment information… PyTorch version: 1.7.0 Is debug build: True CUDA used to build PyTorch: None ROCM used to build PyTorch: N/A

OS: Mac OSX 10.15.7 (x86_64) GCC version: Could not collect Clang version: 12.0.0 (clang-1200.0.32.2) CMake version: Could not collect

Python version: 3.7 (64-bit runtime) Is CUDA available: False CUDA runtime version: No CUDA GPU models and configuration: No CUDA Nvidia driver version: No CUDA cuDNN version: No CUDA HIP runtime version: N/A MIOpen runtime version: N/A

Versions of relevant libraries: [pip3] numpy==1.16.1 [pip3] torch==1.7.0 [pip3] torchvision==0.8.1 [conda] Could not collect

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
NathanHowellcommented, Jan 11, 2021

@edgarriba I’ll have more time next week, in a release push this week.

0reactions
stale[bot]commented, Mar 13, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions, and happy coding day 😎

Read more comments on GitHub >

github_iconTop Results From Across the Web

AttributeError: module 'torchvision.transforms' has no attribute ...
I am running pytorch 0.3.0.post4 on Ubuntu 14.04 (conda 4.3.25, python 3.6.2, cuda 8.0). Here is what I get when importing torchvision.
Read more >
RSNA Screening Mammography Breast Cancer Detection
This augmentation randomly equalizes the histogram of the image, resulting in increased contrast. transforms.RandomEqualize() ...
Read more >
Environment initialized, no module named torch or tensorflow
The reason you're getting "EnvironmentNotWritable Error" is that normal users don't ... import torchvision.transforms as T equalizer = T.RandomEqualize() ...
Read more >
35.2 kB - Hugging Face
getLogger(__name__) def mb_item(x): return x.item() if hasattr(x, "item") else x # checkpoint functions def save_model_checkpoint( model, save_dir, state, ...
Read more >
Error while creating train transform using torch vision
This is why you cannot use transforms.ToTensor() in the torch.nn.Sequential function, as you take an some data as input and transform it to ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found