-
Notifications
You must be signed in to change notification settings - Fork 7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for png decoding on linux
- Pipelines are timing out, increasing to 30 minutes. - Vendors zlib and add's libpng as a dependency. - Ship libpng.so and zlib.so with package on linux
- Loading branch information
Showing
14 changed files
with
293 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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,44 @@ | ||
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.assertEqual(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.assertEqual(img_lpng, img_pil) | ||
|
||
self.assertEqual(decode_png(torch.empty()), torch.empty()) | ||
self.assertEqual(decode_png(torch.randint(3, 5, (300,))), torch.empty()) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
Oops, something went wrong.