Skip to content
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

Added support for CMYK in decode_jpeg #7741

Merged
merged 8 commits into from
Aug 24, 2023

Conversation

vfdev-5
Copy link
Collaborator

@vfdev-5 vfdev-5 commented Jul 13, 2023

Description:

  • Added support for CMYK in decode_jpeg: CMYK -> RGB and CMYK -> GRAY
  • Updated appropriate tests

Fixes #6538

@pytorch-bot
Copy link

pytorch-bot bot commented Jul 13, 2023

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/vision/7741

Note: Links to docs will display an error until the docs builds have been completed.

❌ 30 New Failures, 3 Unrelated Failures

As of commit 5c88b69 with merge base f514ab6 (image):

NEW FAILURES - The following jobs have failed:

FLAKY - The following jobs failed but were likely due to flakiness present on trunk:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@vfdev-5 vfdev-5 changed the title Added support for CMYK in decode_jpeg with mode RGB only Added support for CMYK in decode_jpeg Jul 14, 2023
Copy link
Member

@NicolasHug NicolasHug left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @vfdev-5 , looks good!

torchvision/csrc/io/image/cpu/decode_jpeg.cpp Outdated Show resolved Hide resolved
torchvision/csrc/io/image/cpu/decode_jpeg.cpp Outdated Show resolved Hide resolved
torchvision/csrc/io/image/cpu/decode_jpeg.cpp Outdated Show resolved Hide resolved
torchvision/csrc/io/image/cpu/decode_jpeg.cpp Outdated Show resolved Hide resolved
Copy link
Member

@NicolasHug NicolasHug left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot @vfdev-5

torchvision/csrc/io/image/cpu/decode_jpeg.cpp Outdated Show resolved Hide resolved
torchvision/csrc/io/image/cpu/decode_jpeg.cpp Outdated Show resolved Hide resolved
@vfdev-5
Copy link
Collaborator Author

vfdev-5 commented Aug 17, 2023

How to test decoding on ImageNet:

import PIL.Image as Image
from torchvision.io import read_file, decode_jpeg, ImageReadMode
import numpy as np


for mode in [("unchanged", ImageReadMode.UNCHANGED), ("RGB", ImageReadMode.RGB), ("L", ImageReadMode.GRAY)]:
    for path in [
        "/data/disk0/ImageNet/train/n01739381/n01739381_1309.JPEG",
        "/data/disk0/ImageNet/train/n02077923/n02077923_14822.JPEG",
        "/data/disk0/ImageNet/train/n02447366/n02447366_23489.JPEG",
        "/data/disk0/ImageNet/train/n02492035/n02492035_15739.JPEG",
        "/data/disk0/ImageNet/train/n02747177/n02747177_10752.JPEG",
        "/data/disk0/ImageNet/train/n03018349/n03018349_4028.JPEG",
        "/data/disk0/ImageNet/train/n03062245/n03062245_4620.JPEG",
        "/data/disk0/ImageNet/train/n03347037/n03347037_9675.JPEG",
        "/data/disk0/ImageNet/train/n03467068/n03467068_12171.JPEG",
        "/data/disk0/ImageNet/train/n03529860/n03529860_11437.JPEG",
        "/data/disk0/ImageNet/train/n03544143/n03544143_17228.JPEG",
        "/data/disk0/ImageNet/train/n03633091/n03633091_5218.JPEG",
        "/data/disk0/ImageNet/train/n03710637/n03710637_5125.JPEG",
        "/data/disk0/ImageNet/train/n03961711/n03961711_5286.JPEG",
        "/data/disk0/ImageNet/train/n04033995/n04033995_2932.JPEG",
        "/data/disk0/ImageNet/train/n04258138/n04258138_17003.JPEG",
        "/data/disk0/ImageNet/train/n04264628/n04264628_27969.JPEG",
        "/data/disk0/ImageNet/train/n04336792/n04336792_7448.JPEG",
        "/data/disk0/ImageNet/train/n04371774/n04371774_5854.JPEG",
        "/data/disk0/ImageNet/train/n04596742/n04596742_4225.JPEG",
        "/data/disk0/ImageNet/train/n07583066/n07583066_647.JPEG",
        "/data/disk0/ImageNet/train/n13037406/n13037406_4650.JPEG",
        "/data/disk0/ImageNet/val/n13133613/ILSVRC2012_val_00019877.JPEG",
    ]:
        img = Image.open(path)
        if mode[0] != "unchanged":
            img = img.convert(mode[0])
        np_expected = np.asarray(img)
        if mode[0] == "unchanged":
            np_expected = 255 - np_expected

        data = read_file(path)
        print("\n--", path, mode[0], data.dtype, data.shape, img.mode)
        out = decode_jpeg(data, mode=mode[1])
        np_output = out.permute(1, 2, 0).numpy()

        tol = 0.0
        if mode[1] == ImageReadMode.GRAY:
            np_output = np_output[:, :, 0]

        adiff = np.abs(np_expected.astype("float") - np_output.astype("float"))
        assert adiff.max() < tol + 1e-5, (adiff.max(), path)

@NicolasHug NicolasHug merged commit 4491ca2 into pytorch:main Aug 24, 2023
5 of 14 checks passed
@NicolasHug NicolasHug temporarily deployed to pytorchbot-env August 24, 2023 15:50 — with GitHub Actions Inactive
@NicolasHug NicolasHug temporarily deployed to pytorchbot-env August 24, 2023 15:50 — with GitHub Actions Inactive
@NicolasHug NicolasHug temporarily deployed to pytorchbot-env August 24, 2023 15:50 — with GitHub Actions Inactive
@NicolasHug NicolasHug temporarily deployed to pytorchbot-env August 24, 2023 15:50 — with GitHub Actions Inactive
@NicolasHug NicolasHug temporarily deployed to pytorchbot-env August 24, 2023 15:50 — with GitHub Actions Inactive
@NicolasHug NicolasHug temporarily deployed to pytorchbot-env August 24, 2023 15:51 — with GitHub Actions Inactive
@NicolasHug NicolasHug temporarily deployed to pytorchbot-env August 24, 2023 15:51 — with GitHub Actions Inactive
@NicolasHug NicolasHug temporarily deployed to pytorchbot-env August 24, 2023 15:51 — with GitHub Actions Inactive
@NicolasHug NicolasHug temporarily deployed to pytorchbot-env August 24, 2023 15:51 — with GitHub Actions Inactive
@NicolasHug NicolasHug temporarily deployed to pytorchbot-env August 24, 2023 15:51 — with GitHub Actions Inactive
@vfdev-5 vfdev-5 deleted the issue-6538-support-cmyk branch August 24, 2023 15:52
@NicolasHug NicolasHug temporarily deployed to pytorchbot-env August 24, 2023 15:57 — with GitHub Actions Inactive
facebook-github-bot pushed a commit that referenced this pull request Sep 6, 2023
Summary: (Note: this ignores all push blocking failures!)

Reviewed By: matteobettini

Differential Revision: D48900406

fbshipit-source-id: 05a9d0086cf88677e2249c96638252c8ab92d637

Co-authored-by: Nicolas Hug <nh.nicolas.hug@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for CMYK -> RGB in decode_jpeg()
3 participants