Skip to content

Commit 0854585

Browse files
NicolasHugfacebook-github-bot
authored andcommitted
[fbsync] Expose libavif and heic internally (#8647)
Reviewed By: vmoens Differential Revision: D62581685 fbshipit-source-id: de36dd4d7feab016c101b9070fdcc0838fff4229
1 parent bc7c11f commit 0854585

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

test/test_image.py

+10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55
import re
66
import sys
7+
from contextlib import nullcontext
78
from pathlib import Path
89

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

10781080

1081+
def test_avif_heic_fbcode():
1082+
cm = nullcontext() if IN_FBCODE else pytest.raises(ImportError, match="cannot import")
1083+
with cm:
1084+
from torchvision.io import decode_heic # noqa
1085+
with cm:
1086+
from torchvision.io import decode_avif # noqa
1087+
1088+
10791089
if __name__ == "__main__":
10801090
pytest.main([__file__])

torchvision/_internally_replaced_utils.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
_HOME = os.path.join(_get_torch_home(), "datasets", "vision")
88
_USE_SHARDED_DATASETS = False
9+
IN_FBCODE = False
910

1011

1112
def _download_file_from_remote_location(fpath: str, url: str) -> None:

torchvision/io/__init__.py

+7
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,10 @@
7474
"Video",
7575
"VideoReader",
7676
]
77+
78+
from .._internally_replaced_utils import IN_FBCODE
79+
80+
if IN_FBCODE:
81+
from .image import _decode_avif as decode_avif, _decode_heic as decode_heic
82+
83+
__all__ += ["decode_avif", "decode_heic"]

0 commit comments

Comments
 (0)