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.

16 bits png support and compatibility with current transforms

See original GitHub issue

We 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 to convert_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:open
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
datumboxcommented, Oct 25, 2021

@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.

1reaction
h-vetinaricommented, Mar 21, 2022

If I had to take a wild guess, I would bet that your CI pipeline is setup in such a way that 16 is part of the path to the images, even those that aren’t 16bits images. From your logs the image paths look like img_path = '$SRC_DIR/test/assets/fakedata/logos/gray_pytorch.png'. Does $SRC_DIR contain 16?

That was a great guess:

## Package Plan ##

  environment location: /home/conda/feedstock_root/build_artifacts/torchvision-split_1647851964444/_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehol

If that’s the case please let us know and we’ll make that check more robust

That would be wonderful, thanks a lot! 🙃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Read 16-bit PNG image file using Python - Stack Overflow
The data should be converted to a NumPy array. But I have no idea how to read the file in '16-bit'. I tried...
Read more >
PNG 16 Technical
Although the PNG specification supports greyscale imagery of 16-bits per pixel, ... the only current choice is use the PNG format with 48...
Read more >
Chapter 11: PNG Options and Extensions - libpng.org
PNG supports two types of Latin-1-based text chunks, uncompressed (tEXt) and compressed (zTXt). There is also a new Unicode-based chunk (iTXt) that I'll ......
Read more >
Portable Network Graphics (PNG) Specification (Second Edition)
Indexed-colour, greyscale, and truecolour images are supported, with optional transparency. Sample depths range from 1 to 16 bits. PNG is ...
Read more >
Understanding File Types, Bit Depth, Image Data Size. With ...
24-bit RGB photo data is always 3 bytes per pixel (when uncompressed for use). 24-bit PNG is lossless for photos, and TIF with...
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