Skip to content

Commit

Permalink
Expose libavif and heic internally (#8647)
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasHug committed Sep 12, 2024
1 parent 7eb09df commit 6d7851b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
10 changes: 10 additions & 0 deletions test/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import re
import sys
from contextlib import nullcontext
from pathlib import Path

import numpy as np
Expand All @@ -13,6 +14,7 @@
import torchvision.transforms.v2.functional as F
from common_utils import assert_equal, cpu_and_cuda, IN_OSS_CI, needs_cuda
from PIL import __version__ as PILLOW_VERSION, Image, ImageOps, ImageSequence
from torchvision._internally_replaced_utils import IN_FBCODE
from torchvision.io.image import (
_decode_avif,
_decode_heic,
Expand Down Expand Up @@ -1076,5 +1078,13 @@ def test_mode_str():
assert decode_image(path, mode="RGBA").shape[0] == 4


def test_avif_heic_fbcode():
cm = nullcontext() if IN_FBCODE else pytest.raises(ImportError, match="cannot import")
with cm:
from torchvision.io import decode_heic # noqa
with cm:
from torchvision.io import decode_avif # noqa


if __name__ == "__main__":
pytest.main([__file__])
1 change: 1 addition & 0 deletions torchvision/_internally_replaced_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

_HOME = os.path.join(_get_torch_home(), "datasets", "vision")
_USE_SHARDED_DATASETS = False
IN_FBCODE = False


def _download_file_from_remote_location(fpath: str, url: str) -> None:
Expand Down
7 changes: 7 additions & 0 deletions torchvision/io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,10 @@
"Video",
"VideoReader",
]

from .._internally_replaced_utils import IN_FBCODE

if IN_FBCODE:
from .image import _decode_avif as decode_avif, _decode_heic as decode_heic

__all__ += ["decode_avif", "decode_heic"]

0 comments on commit 6d7851b

Please sign in to comment.