66
77import torch
88import torchvision
9- from torchvision .io import decode_image , decode_jpeg , decode_webp , read_file
9+ from torchvision .io import decode_avif , decode_heic , decode_image , decode_jpeg , read_file
1010from torchvision .models import resnet50 , ResNet50_Weights
1111
1212
@@ -24,13 +24,36 @@ def smoke_test_torchvision_read_decode() -> None:
2424 img_jpg = decode_image (str (SCRIPT_DIR / "assets" / "encode_jpeg" / "grace_hopper_517x606.jpg" ))
2525 if img_jpg .shape != (3 , 606 , 517 ):
2626 raise RuntimeError (f"Unexpected shape of img_jpg: { img_jpg .shape } " )
27+
2728 img_png = decode_image (str (SCRIPT_DIR / "assets" / "interlaced_png" / "wizard_low.png" ))
2829 if img_png .shape != (4 , 471 , 354 ):
2930 raise RuntimeError (f"Unexpected shape of img_png: { img_png .shape } " )
31+
3032 img_webp = decode_image (str (SCRIPT_DIR / "assets/fakedata/logos/rgb_pytorch.webp" ))
3133 if img_webp .shape != (3 , 100 , 100 ):
3234 raise RuntimeError (f"Unexpected shape of img_webp: { img_webp .shape } " )
3335
36+ if sys .platform == "linux" :
37+ img_avif = decode_avif (str (SCRIPT_DIR / "assets/fakedata/logos/rgb_pytorch.avif" ))
38+ if img_avif .shape != (3 , 100 , 100 ):
39+ raise RuntimeError (f"Unexpected shape of img_avif: { img_avif .shape } " )
40+
41+ img_heic = decode_heic (
42+ str (SCRIPT_DIR / "assets/fakedata/logos/rgb_pytorch_incorrectly_encoded_but_who_cares.heic" )
43+ )
44+ if img_heic .shape != (3 , 100 , 100 ):
45+ raise RuntimeError (f"Unexpected shape of img_heic: { img_heic .shape } " )
46+ else :
47+ try :
48+ decode_avif (str (SCRIPT_DIR / "assets/fakedata/logos/rgb_pytorch.avif" ))
49+ except RuntimeError as e :
50+ assert "torchvision-extra-decoders" in str (e )
51+
52+ try :
53+ decode_heic (str (SCRIPT_DIR / "assets/fakedata/logos/rgb_pytorch_incorrectly_encoded_but_who_cares.heic" ))
54+ except RuntimeError as e :
55+ assert "torchvision-extra-decoders" in str (e )
56+
3457
3558def smoke_test_torchvision_decode_jpeg (device : str = "cpu" ):
3659 img_jpg_data = read_file (str (SCRIPT_DIR / "assets" / "encode_jpeg" / "grace_hopper_517x606.jpg" ))
0 commit comments