-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Add support for png decoding on linux #1881
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
978d41e
Add support for png decoding on linux
r-zenine daba9d0
Fix windows pipeline error
r-zenine e758748
Statically linking zlib and libpng
r-zenine 7ee1d02
Add's support for macos
r-zenine 7d757ac
Improve errors handling and fix unit tests
r-zenine 08a70af
Attempt to fix conda builds
r-zenine e264be1
Revert "Statically linking zlib and libpng"
r-zenine 75f4130
drops mac support for now
r-zenine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[submodule "third_party/libpng"] | ||
path = third_party/libpng | ||
url = https://github.com/glennrp/libpng | ||
[submodule "third_party/zlib"] | ||
path = third_party/zlib | ||
url = https://github.com/madler/zlib |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import os | ||
import unittest | ||
import sys | ||
|
||
import torch | ||
from PIL import Image | ||
if sys.platform.startswith('linux'): | ||
from torchvision.io.image import read_png, decode_png | ||
import numpy as np | ||
|
||
IMAGE_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "assets", "fakedata", "imagefolder") | ||
|
||
|
||
def get_images(directory, img_ext): | ||
assert os.path.isdir(directory) | ||
for root, dir, files in os.walk(directory): | ||
for fl in files: | ||
_, ext = os.path.splitext(fl) | ||
if ext == img_ext: | ||
yield os.path.join(root, fl) | ||
|
||
|
||
class ImageTester(unittest.TestCase): | ||
@unittest.skipUnless(sys.platform.startswith("linux"), "Support only available on linux for now.") | ||
def test_read_png(self): | ||
for img_path in get_images(IMAGE_DIR, ".png"): | ||
img_pil = torch.from_numpy(np.array(Image.open(img_path))) | ||
img_lpng = read_png(img_path) | ||
self.assertTrue(torch.equal(img_lpng, img_pil)) | ||
|
||
@unittest.skipUnless(sys.platform.startswith("linux"), "Support only available on linux for now.") | ||
def test_decode_png(self): | ||
for img_path in get_images(IMAGE_DIR, ".png"): | ||
img_pil = torch.from_numpy(np.array(Image.open(img_path))) | ||
size = os.path.getsize(img_path) | ||
img_lpng = decode_png(torch.from_file(img_path, dtype=torch.uint8, size=size)) | ||
self.assertTrue(torch.equal(img_lpng, img_pil)) | ||
|
||
with self.assertRaisesRegex(ValueError, "Expected a non empty 1-dimensional tensor."): | ||
decode_png(torch.empty((100, 1), dtype=torch.uint8)) | ||
|
||
with self.assertRaisesRegex(ValueError, "Expected a torch.uint8 tensor."): | ||
decode_png(torch.empty((100, ), dtype=torch.float16)) | ||
|
||
with self.assertRaisesRegex(ValueError, "Invalid png input."): | ||
decode_png(torch.empty((100), dtype=torch.uint8)) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.