Add support for decoding 16bits png #8524
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds support for decoding 16bits png in
read_image,decode_imageanddecode_png.It also adds proper support and tests to convert the resuting
torch.uint16tensor into uint8/float32 tensor viato_dtype().Note: decoding 16bits pngs was previously supported via a private API that we had to enable to support RAFT. At the time, the
torch.uint16dtype didn't exist, so we had to return atorch.int32tensor. Support fortorch.uint16was recently added in pytorch. The dtype exists, but very few operators are implemented for it. In our decoder docs, we strongly encourage users to callto_dtype(..., scale=True)to convert the resulting uint16 tensor into a supported dtype like uint8 or float.Re the "old" v1
F.convert_image_dtype(): uint16 -> float32 works, but-> uint8fails with a loud error. It's OK, we want users to use the v2to_dtypeanyway.Closes #4731