-
Notifications
You must be signed in to change notification settings - Fork 7.2k
Vectorize the equalize transformation #3173
Copy link
Copy link
Closed
Description
🚀 Feature
The current implementation of the equalize transformation is not vectorized. It processes each channel of each image of the batch using a for loop. This is done because the method uses internally the torch.histc which currently can't produce a histogram across a dimension.
vision/torchvision/transforms/functional_tensor.py
Lines 1281 to 1282 in 83171d6
| def _scale_channel(img_chan): | |
| hist = torch.histc(img_chan.to(torch.float32), bins=256, min=0, max=255) |
@fmassa proposed a workaround that trades memory for speed and achieves vectorization. Check #3123 (comment) for the overview/context of the proposal.
To adopt his, a few addtional changes need to be made:
- The rest of the
_scale_channel()needs to be adapted to vectorize the remaining operations. - The
_equalize_single_image()needs to be removed and the stacking operation inequalize()need to be adapted.
Reactions are currently unavailable