24
24
import torch .nn .functional as F
25
25
from common_utils import combinations_grid
26
26
from torchvision import datasets
27
+ from torchvision .io import decode_image
27
28
from torchvision .transforms import v2
28
29
29
30
@@ -405,6 +406,8 @@ class ImageNetTestCase(datasets_utils.ImageDatasetTestCase):
405
406
REQUIRED_PACKAGES = ("scipy" ,)
406
407
ADDITIONAL_CONFIGS = combinations_grid (split = ("train" , "val" ))
407
408
409
+ SUPPORT_TV_IMAGE_DECODE = True
410
+
408
411
def inject_fake_data (self , tmpdir , config ):
409
412
tmpdir = pathlib .Path (tmpdir )
410
413
@@ -1173,6 +1176,8 @@ class SBUTestCase(datasets_utils.ImageDatasetTestCase):
1173
1176
DATASET_CLASS = datasets .SBU
1174
1177
FEATURE_TYPES = (PIL .Image .Image , str )
1175
1178
1179
+ SUPPORT_TV_IMAGE_DECODE = True
1180
+
1176
1181
def inject_fake_data (self , tmpdir , config ):
1177
1182
num_images = 3
1178
1183
@@ -1411,6 +1416,8 @@ class Flickr8kTestCase(datasets_utils.ImageDatasetTestCase):
1411
1416
_IMAGES_FOLDER = "images"
1412
1417
_ANNOTATIONS_FILE = "captions.html"
1413
1418
1419
+ SUPPORT_TV_IMAGE_DECODE = True
1420
+
1414
1421
def dataset_args (self , tmpdir , config ):
1415
1422
tmpdir = pathlib .Path (tmpdir )
1416
1423
root = tmpdir / self ._IMAGES_FOLDER
@@ -1480,6 +1487,8 @@ class Flickr30kTestCase(Flickr8kTestCase):
1480
1487
1481
1488
_ANNOTATIONS_FILE = "captions.token"
1482
1489
1490
+ SUPPORT_TV_IMAGE_DECODE = True
1491
+
1483
1492
def _image_file_name (self , idx ):
1484
1493
return f"{ idx } .jpg"
1485
1494
@@ -1940,6 +1949,8 @@ class LFWPeopleTestCase(datasets_utils.DatasetTestCase):
1940
1949
_IMAGES_DIR = {"original" : "lfw" , "funneled" : "lfw_funneled" , "deepfunneled" : "lfw-deepfunneled" }
1941
1950
_file_id = {"10fold" : "" , "train" : "DevTrain" , "test" : "DevTest" }
1942
1951
1952
+ SUPPORT_TV_IMAGE_DECODE = True
1953
+
1943
1954
def inject_fake_data (self , tmpdir , config ):
1944
1955
tmpdir = pathlib .Path (tmpdir ) / "lfw-py"
1945
1956
os .makedirs (tmpdir , exist_ok = True )
@@ -1976,6 +1987,18 @@ def _create_random_id(self):
1976
1987
part2 = datasets_utils .create_random_string (random .randint (4 , 7 ))
1977
1988
return f"{ part1 } _{ part2 } "
1978
1989
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
+
1979
2002
1980
2003
class LFWPairsTestCase (LFWPeopleTestCase ):
1981
2004
DATASET_CLASS = datasets .LFWPairs
@@ -2308,6 +2331,7 @@ def inject_fake_data(self, tmpdir, config):
2308
2331
class EuroSATTestCase (datasets_utils .ImageDatasetTestCase ):
2309
2332
DATASET_CLASS = datasets .EuroSAT
2310
2333
FEATURE_TYPES = (PIL .Image .Image , int )
2334
+ SUPPORT_TV_IMAGE_DECODE = True
2311
2335
2312
2336
def inject_fake_data (self , tmpdir , config ):
2313
2337
data_folder = os .path .join (tmpdir , "eurosat" , "2750" )
@@ -2332,6 +2356,8 @@ class Food101TestCase(datasets_utils.ImageDatasetTestCase):
2332
2356
2333
2357
ADDITIONAL_CONFIGS = combinations_grid (split = ("train" , "test" ))
2334
2358
2359
+ SUPPORT_TV_IMAGE_DECODE = True
2360
+
2335
2361
def inject_fake_data (self , tmpdir : str , config ):
2336
2362
root_folder = pathlib .Path (tmpdir ) / "food-101"
2337
2363
image_folder = root_folder / "images"
@@ -2368,6 +2394,7 @@ class FGVCAircraftTestCase(datasets_utils.ImageDatasetTestCase):
2368
2394
ADDITIONAL_CONFIGS = combinations_grid (
2369
2395
split = ("train" , "val" , "trainval" , "test" ), annotation_level = ("variant" , "family" , "manufacturer" )
2370
2396
)
2397
+ SUPPORT_TV_IMAGE_DECODE = True
2371
2398
2372
2399
def inject_fake_data (self , tmpdir : str , config ):
2373
2400
split = config ["split" ]
@@ -2417,6 +2444,8 @@ def inject_fake_data(self, tmpdir: str, config):
2417
2444
class SUN397TestCase (datasets_utils .ImageDatasetTestCase ):
2418
2445
DATASET_CLASS = datasets .SUN397
2419
2446
2447
+ SUPPORT_TV_IMAGE_DECODE = True
2448
+
2420
2449
def inject_fake_data (self , tmpdir : str , config ):
2421
2450
data_dir = pathlib .Path (tmpdir ) / "SUN397"
2422
2451
data_dir .mkdir ()
@@ -2448,6 +2477,8 @@ class DTDTestCase(datasets_utils.ImageDatasetTestCase):
2448
2477
DATASET_CLASS = datasets .DTD
2449
2478
FEATURE_TYPES = (PIL .Image .Image , int )
2450
2479
2480
+ SUPPORT_TV_IMAGE_DECODE = True
2481
+
2451
2482
ADDITIONAL_CONFIGS = combinations_grid (
2452
2483
split = ("train" , "test" , "val" ),
2453
2484
# 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):
2608
2639
FEATURE_TYPES = (PIL .Image .Image , (int , type (None )))
2609
2640
2610
2641
ADDITIONAL_CONFIGS = combinations_grid (split = ("train" , "val" , "test" ))
2642
+ SUPPORT_TV_IMAGE_DECODE = True
2611
2643
2612
2644
def inject_fake_data (self , tmpdir , config ):
2613
2645
data_folder = pathlib .Path (tmpdir ) / "clevr" / "CLEVR_v1.0"
@@ -2705,6 +2737,8 @@ class StanfordCarsTestCase(datasets_utils.ImageDatasetTestCase):
2705
2737
REQUIRED_PACKAGES = ("scipy" ,)
2706
2738
ADDITIONAL_CONFIGS = combinations_grid (split = ("train" , "test" ))
2707
2739
2740
+ SUPPORT_TV_IMAGE_DECODE = True
2741
+
2708
2742
def inject_fake_data (self , tmpdir , config ):
2709
2743
import scipy .io as io
2710
2744
from numpy .core .records import fromarrays
@@ -2749,6 +2783,8 @@ class Country211TestCase(datasets_utils.ImageDatasetTestCase):
2749
2783
2750
2784
ADDITIONAL_CONFIGS = combinations_grid (split = ("train" , "valid" , "test" ))
2751
2785
2786
+ SUPPORT_TV_IMAGE_DECODE = True
2787
+
2752
2788
def inject_fake_data (self , tmpdir : str , config ):
2753
2789
split_folder = pathlib .Path (tmpdir ) / "country211" / config ["split" ]
2754
2790
split_folder .mkdir (parents = True , exist_ok = True )
@@ -2777,6 +2813,8 @@ class Flowers102TestCase(datasets_utils.ImageDatasetTestCase):
2777
2813
ADDITIONAL_CONFIGS = combinations_grid (split = ("train" , "val" , "test" ))
2778
2814
REQUIRED_PACKAGES = ("scipy" ,)
2779
2815
2816
+ SUPPORT_TV_IMAGE_DECODE = True
2817
+
2780
2818
def inject_fake_data (self , tmpdir : str , config ):
2781
2819
base_folder = pathlib .Path (tmpdir ) / "flowers-102"
2782
2820
@@ -2835,6 +2873,8 @@ class RenderedSST2TestCase(datasets_utils.ImageDatasetTestCase):
2835
2873
ADDITIONAL_CONFIGS = combinations_grid (split = ("train" , "val" , "test" ))
2836
2874
SPLIT_TO_FOLDER = {"train" : "train" , "val" : "valid" , "test" : "test" }
2837
2875
2876
+ SUPPORT_TV_IMAGE_DECODE = True
2877
+
2838
2878
def inject_fake_data (self , tmpdir : str , config ):
2839
2879
root_folder = pathlib .Path (tmpdir ) / "rendered-sst2"
2840
2880
image_folder = root_folder / self .SPLIT_TO_FOLDER [config ["split" ]]
@@ -3495,6 +3535,8 @@ class ImagenetteTestCase(datasets_utils.ImageDatasetTestCase):
3495
3535
DATASET_CLASS = datasets .Imagenette
3496
3536
ADDITIONAL_CONFIGS = combinations_grid (split = ["train" , "val" ], size = ["full" , "320px" , "160px" ])
3497
3537
3538
+ SUPPORT_TV_IMAGE_DECODE = True
3539
+
3498
3540
_WNIDS = [
3499
3541
"n01440764" ,
3500
3542
"n02102040" ,
0 commit comments