2424import torch .nn .functional as F
2525from common_utils import combinations_grid
2626from torchvision import datasets
27+ from torchvision .io import decode_image
2728from torchvision .transforms import v2
2829
2930
@@ -405,6 +406,8 @@ class ImageNetTestCase(datasets_utils.ImageDatasetTestCase):
405406 REQUIRED_PACKAGES = ("scipy" ,)
406407 ADDITIONAL_CONFIGS = combinations_grid (split = ("train" , "val" ))
407408
409+ SUPPORT_TV_IMAGE_DECODE = True
410+
408411 def inject_fake_data (self , tmpdir , config ):
409412 tmpdir = pathlib .Path (tmpdir )
410413
@@ -1173,6 +1176,8 @@ class SBUTestCase(datasets_utils.ImageDatasetTestCase):
11731176 DATASET_CLASS = datasets .SBU
11741177 FEATURE_TYPES = (PIL .Image .Image , str )
11751178
1179+ SUPPORT_TV_IMAGE_DECODE = True
1180+
11761181 def inject_fake_data (self , tmpdir , config ):
11771182 num_images = 3
11781183
@@ -1411,6 +1416,8 @@ class Flickr8kTestCase(datasets_utils.ImageDatasetTestCase):
14111416 _IMAGES_FOLDER = "images"
14121417 _ANNOTATIONS_FILE = "captions.html"
14131418
1419+ SUPPORT_TV_IMAGE_DECODE = True
1420+
14141421 def dataset_args (self , tmpdir , config ):
14151422 tmpdir = pathlib .Path (tmpdir )
14161423 root = tmpdir / self ._IMAGES_FOLDER
@@ -1480,6 +1487,8 @@ class Flickr30kTestCase(Flickr8kTestCase):
14801487
14811488 _ANNOTATIONS_FILE = "captions.token"
14821489
1490+ SUPPORT_TV_IMAGE_DECODE = True
1491+
14831492 def _image_file_name (self , idx ):
14841493 return f"{ idx } .jpg"
14851494
@@ -1940,6 +1949,8 @@ class LFWPeopleTestCase(datasets_utils.DatasetTestCase):
19401949 _IMAGES_DIR = {"original" : "lfw" , "funneled" : "lfw_funneled" , "deepfunneled" : "lfw-deepfunneled" }
19411950 _file_id = {"10fold" : "" , "train" : "DevTrain" , "test" : "DevTest" }
19421951
1952+ SUPPORT_TV_IMAGE_DECODE = True
1953+
19431954 def inject_fake_data (self , tmpdir , config ):
19441955 tmpdir = pathlib .Path (tmpdir ) / "lfw-py"
19451956 os .makedirs (tmpdir , exist_ok = True )
@@ -1976,6 +1987,18 @@ def _create_random_id(self):
19761987 part2 = datasets_utils .create_random_string (random .randint (4 , 7 ))
19771988 return f"{ part1 } _{ part2 } "
19781989
1990+ def test_tv_decode_image_support (self ):
1991+ if not self .SUPPORT_TV_IMAGE_DECODE :
1992+ pytest .skip (f"{ self .DATASET_CLASS .__name__ } does not support torchvision.io.decode_image." )
1993+
1994+ with self .create_dataset (
1995+ config = dict (
1996+ loader = decode_image ,
1997+ )
1998+ ) as (dataset , _ ):
1999+ image = dataset [0 ][0 ]
2000+ assert isinstance (image , torch .Tensor )
2001+
19792002
19802003class LFWPairsTestCase (LFWPeopleTestCase ):
19812004 DATASET_CLASS = datasets .LFWPairs
@@ -2308,6 +2331,7 @@ def inject_fake_data(self, tmpdir, config):
23082331class EuroSATTestCase (datasets_utils .ImageDatasetTestCase ):
23092332 DATASET_CLASS = datasets .EuroSAT
23102333 FEATURE_TYPES = (PIL .Image .Image , int )
2334+ SUPPORT_TV_IMAGE_DECODE = True
23112335
23122336 def inject_fake_data (self , tmpdir , config ):
23132337 data_folder = os .path .join (tmpdir , "eurosat" , "2750" )
@@ -2332,6 +2356,8 @@ class Food101TestCase(datasets_utils.ImageDatasetTestCase):
23322356
23332357 ADDITIONAL_CONFIGS = combinations_grid (split = ("train" , "test" ))
23342358
2359+ SUPPORT_TV_IMAGE_DECODE = True
2360+
23352361 def inject_fake_data (self , tmpdir : str , config ):
23362362 root_folder = pathlib .Path (tmpdir ) / "food-101"
23372363 image_folder = root_folder / "images"
@@ -2368,6 +2394,7 @@ class FGVCAircraftTestCase(datasets_utils.ImageDatasetTestCase):
23682394 ADDITIONAL_CONFIGS = combinations_grid (
23692395 split = ("train" , "val" , "trainval" , "test" ), annotation_level = ("variant" , "family" , "manufacturer" )
23702396 )
2397+ SUPPORT_TV_IMAGE_DECODE = True
23712398
23722399 def inject_fake_data (self , tmpdir : str , config ):
23732400 split = config ["split" ]
@@ -2417,6 +2444,8 @@ def inject_fake_data(self, tmpdir: str, config):
24172444class SUN397TestCase (datasets_utils .ImageDatasetTestCase ):
24182445 DATASET_CLASS = datasets .SUN397
24192446
2447+ SUPPORT_TV_IMAGE_DECODE = True
2448+
24202449 def inject_fake_data (self , tmpdir : str , config ):
24212450 data_dir = pathlib .Path (tmpdir ) / "SUN397"
24222451 data_dir .mkdir ()
@@ -2448,6 +2477,8 @@ class DTDTestCase(datasets_utils.ImageDatasetTestCase):
24482477 DATASET_CLASS = datasets .DTD
24492478 FEATURE_TYPES = (PIL .Image .Image , int )
24502479
2480+ SUPPORT_TV_IMAGE_DECODE = True
2481+
24512482 ADDITIONAL_CONFIGS = combinations_grid (
24522483 split = ("train" , "test" , "val" ),
24532484 # There is no need to test the whole matrix here, since each fold is treated exactly the same
@@ -2608,6 +2639,7 @@ class CLEVRClassificationTestCase(datasets_utils.ImageDatasetTestCase):
26082639 FEATURE_TYPES = (PIL .Image .Image , (int , type (None )))
26092640
26102641 ADDITIONAL_CONFIGS = combinations_grid (split = ("train" , "val" , "test" ))
2642+ SUPPORT_TV_IMAGE_DECODE = True
26112643
26122644 def inject_fake_data (self , tmpdir , config ):
26132645 data_folder = pathlib .Path (tmpdir ) / "clevr" / "CLEVR_v1.0"
@@ -2705,6 +2737,8 @@ class StanfordCarsTestCase(datasets_utils.ImageDatasetTestCase):
27052737 REQUIRED_PACKAGES = ("scipy" ,)
27062738 ADDITIONAL_CONFIGS = combinations_grid (split = ("train" , "test" ))
27072739
2740+ SUPPORT_TV_IMAGE_DECODE = True
2741+
27082742 def inject_fake_data (self , tmpdir , config ):
27092743 import scipy .io as io
27102744 from numpy .core .records import fromarrays
@@ -2749,6 +2783,8 @@ class Country211TestCase(datasets_utils.ImageDatasetTestCase):
27492783
27502784 ADDITIONAL_CONFIGS = combinations_grid (split = ("train" , "valid" , "test" ))
27512785
2786+ SUPPORT_TV_IMAGE_DECODE = True
2787+
27522788 def inject_fake_data (self , tmpdir : str , config ):
27532789 split_folder = pathlib .Path (tmpdir ) / "country211" / config ["split" ]
27542790 split_folder .mkdir (parents = True , exist_ok = True )
@@ -2777,6 +2813,8 @@ class Flowers102TestCase(datasets_utils.ImageDatasetTestCase):
27772813 ADDITIONAL_CONFIGS = combinations_grid (split = ("train" , "val" , "test" ))
27782814 REQUIRED_PACKAGES = ("scipy" ,)
27792815
2816+ SUPPORT_TV_IMAGE_DECODE = True
2817+
27802818 def inject_fake_data (self , tmpdir : str , config ):
27812819 base_folder = pathlib .Path (tmpdir ) / "flowers-102"
27822820
@@ -2835,6 +2873,8 @@ class RenderedSST2TestCase(datasets_utils.ImageDatasetTestCase):
28352873 ADDITIONAL_CONFIGS = combinations_grid (split = ("train" , "val" , "test" ))
28362874 SPLIT_TO_FOLDER = {"train" : "train" , "val" : "valid" , "test" : "test" }
28372875
2876+ SUPPORT_TV_IMAGE_DECODE = True
2877+
28382878 def inject_fake_data (self , tmpdir : str , config ):
28392879 root_folder = pathlib .Path (tmpdir ) / "rendered-sst2"
28402880 image_folder = root_folder / self .SPLIT_TO_FOLDER [config ["split" ]]
@@ -3495,6 +3535,8 @@ class ImagenetteTestCase(datasets_utils.ImageDatasetTestCase):
34953535 DATASET_CLASS = datasets .Imagenette
34963536 ADDITIONAL_CONFIGS = combinations_grid (split = ["train" , "val" ], size = ["full" , "320px" , "160px" ])
34973537
3538+ SUPPORT_TV_IMAGE_DECODE = True
3539+
34983540 _WNIDS = [
34993541 "n01440764" ,
35003542 "n02102040" ,
0 commit comments