16 bits png support and compatibility with current transforms
See original GitHub issueWe added support for decoding 16 bit pngs in https://github.com/pytorch/vision/pull/4657.
Pytorch doesn’t support uint16
dtype, so we have to return a int32
tenor instead. However as @nairbv pointed out, this can lead to unexpected behaviour for the convert_image_dtype()
, because this function relies on the max value of a given dtype to carry the conversions.
While the actual max value of a 16 bits image is 2**16 - 1
, convert_image_dtype()
will assume that it’s (2**31 - 1)
because the image is in a int32
tensor. This leads to e.g. a tensor full of zeros when converting to uint8.
Potential solutions are:
- native support for int16 in pytorch
- add a new
input_range=None
parameter toconvert_image_dtype()
(not a fan of that)
For now, I’ll just make this a private API (e.g. _decode_16bits_png()
or something). It will still allow to continue the work on RAFT, which was the main reason I needed 16bits decoding in the first place.
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (4 by maintainers)
Top GitHub Comments
@NicolasHug I’ll try to have a look to get these examples. Another idea discussed on Github issues was also to store this information on the new Image classes that @pmeier is working on. This way we won’t have to pass an extra parameter and we can read this info directly from the input tensor meta-data.
That was a great guess:
That would be wonderful, thanks a lot! 🙃