|
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 |
|
@@ -1175,6 +1176,8 @@ class SBUTestCase(datasets_utils.ImageDatasetTestCase): |
1175 | 1176 | DATASET_CLASS = datasets.SBU |
1176 | 1177 | FEATURE_TYPES = (PIL.Image.Image, str) |
1177 | 1178 |
|
| 1179 | + SUPPORT_TV_IMAGE_DECODE = True |
| 1180 | + |
1178 | 1181 | def inject_fake_data(self, tmpdir, config): |
1179 | 1182 | num_images = 3 |
1180 | 1183 |
|
@@ -1413,6 +1416,8 @@ class Flickr8kTestCase(datasets_utils.ImageDatasetTestCase): |
1413 | 1416 | _IMAGES_FOLDER = "images" |
1414 | 1417 | _ANNOTATIONS_FILE = "captions.html" |
1415 | 1418 |
|
| 1419 | + SUPPORT_TV_IMAGE_DECODE = True |
| 1420 | + |
1416 | 1421 | def dataset_args(self, tmpdir, config): |
1417 | 1422 | tmpdir = pathlib.Path(tmpdir) |
1418 | 1423 | root = tmpdir / self._IMAGES_FOLDER |
@@ -1482,6 +1487,8 @@ class Flickr30kTestCase(Flickr8kTestCase): |
1482 | 1487 |
|
1483 | 1488 | _ANNOTATIONS_FILE = "captions.token" |
1484 | 1489 |
|
| 1490 | + SUPPORT_TV_IMAGE_DECODE = True |
| 1491 | + |
1485 | 1492 | def _image_file_name(self, idx): |
1486 | 1493 | return f"{idx}.jpg" |
1487 | 1494 |
|
@@ -1942,6 +1949,8 @@ class LFWPeopleTestCase(datasets_utils.DatasetTestCase): |
1942 | 1949 | _IMAGES_DIR = {"original": "lfw", "funneled": "lfw_funneled", "deepfunneled": "lfw-deepfunneled"} |
1943 | 1950 | _file_id = {"10fold": "", "train": "DevTrain", "test": "DevTest"} |
1944 | 1951 |
|
| 1952 | + SUPPORT_TV_IMAGE_DECODE = True |
| 1953 | + |
1945 | 1954 | def inject_fake_data(self, tmpdir, config): |
1946 | 1955 | tmpdir = pathlib.Path(tmpdir) / "lfw-py" |
1947 | 1956 | os.makedirs(tmpdir, exist_ok=True) |
@@ -1978,6 +1987,18 @@ def _create_random_id(self): |
1978 | 1987 | part2 = datasets_utils.create_random_string(random.randint(4, 7)) |
1979 | 1988 | return f"{part1}_{part2}" |
1980 | 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 | + |
1981 | 2002 |
|
1982 | 2003 | class LFWPairsTestCase(LFWPeopleTestCase): |
1983 | 2004 | DATASET_CLASS = datasets.LFWPairs |
@@ -2335,6 +2356,8 @@ class Food101TestCase(datasets_utils.ImageDatasetTestCase): |
2335 | 2356 |
|
2336 | 2357 | ADDITIONAL_CONFIGS = combinations_grid(split=("train", "test")) |
2337 | 2358 |
|
| 2359 | + SUPPORT_TV_IMAGE_DECODE = True |
| 2360 | + |
2338 | 2361 | def inject_fake_data(self, tmpdir: str, config): |
2339 | 2362 | root_folder = pathlib.Path(tmpdir) / "food-101" |
2340 | 2363 | image_folder = root_folder / "images" |
@@ -2371,6 +2394,7 @@ class FGVCAircraftTestCase(datasets_utils.ImageDatasetTestCase): |
2371 | 2394 | ADDITIONAL_CONFIGS = combinations_grid( |
2372 | 2395 | split=("train", "val", "trainval", "test"), annotation_level=("variant", "family", "manufacturer") |
2373 | 2396 | ) |
| 2397 | + SUPPORT_TV_IMAGE_DECODE = True |
2374 | 2398 |
|
2375 | 2399 | def inject_fake_data(self, tmpdir: str, config): |
2376 | 2400 | split = config["split"] |
@@ -2420,6 +2444,8 @@ def inject_fake_data(self, tmpdir: str, config): |
2420 | 2444 | class SUN397TestCase(datasets_utils.ImageDatasetTestCase): |
2421 | 2445 | DATASET_CLASS = datasets.SUN397 |
2422 | 2446 |
|
| 2447 | + SUPPORT_TV_IMAGE_DECODE = True |
| 2448 | + |
2423 | 2449 | def inject_fake_data(self, tmpdir: str, config): |
2424 | 2450 | data_dir = pathlib.Path(tmpdir) / "SUN397" |
2425 | 2451 | data_dir.mkdir() |
@@ -2451,6 +2477,8 @@ class DTDTestCase(datasets_utils.ImageDatasetTestCase): |
2451 | 2477 | DATASET_CLASS = datasets.DTD |
2452 | 2478 | FEATURE_TYPES = (PIL.Image.Image, int) |
2453 | 2479 |
|
| 2480 | + SUPPORT_TV_IMAGE_DECODE = True |
| 2481 | + |
2454 | 2482 | ADDITIONAL_CONFIGS = combinations_grid( |
2455 | 2483 | split=("train", "test", "val"), |
2456 | 2484 | # There is no need to test the whole matrix here, since each fold is treated exactly the same |
@@ -2611,6 +2639,7 @@ class CLEVRClassificationTestCase(datasets_utils.ImageDatasetTestCase): |
2611 | 2639 | FEATURE_TYPES = (PIL.Image.Image, (int, type(None))) |
2612 | 2640 |
|
2613 | 2641 | ADDITIONAL_CONFIGS = combinations_grid(split=("train", "val", "test")) |
| 2642 | + SUPPORT_TV_IMAGE_DECODE = True |
2614 | 2643 |
|
2615 | 2644 | def inject_fake_data(self, tmpdir, config): |
2616 | 2645 | data_folder = pathlib.Path(tmpdir) / "clevr" / "CLEVR_v1.0" |
@@ -2708,6 +2737,8 @@ class StanfordCarsTestCase(datasets_utils.ImageDatasetTestCase): |
2708 | 2737 | REQUIRED_PACKAGES = ("scipy",) |
2709 | 2738 | ADDITIONAL_CONFIGS = combinations_grid(split=("train", "test")) |
2710 | 2739 |
|
| 2740 | + SUPPORT_TV_IMAGE_DECODE = True |
| 2741 | + |
2711 | 2742 | def inject_fake_data(self, tmpdir, config): |
2712 | 2743 | import scipy.io as io |
2713 | 2744 | from numpy.core.records import fromarrays |
@@ -2782,6 +2813,8 @@ class Flowers102TestCase(datasets_utils.ImageDatasetTestCase): |
2782 | 2813 | ADDITIONAL_CONFIGS = combinations_grid(split=("train", "val", "test")) |
2783 | 2814 | REQUIRED_PACKAGES = ("scipy",) |
2784 | 2815 |
|
| 2816 | + SUPPORT_TV_IMAGE_DECODE = True |
| 2817 | + |
2785 | 2818 | def inject_fake_data(self, tmpdir: str, config): |
2786 | 2819 | base_folder = pathlib.Path(tmpdir) / "flowers-102" |
2787 | 2820 |
|
@@ -2840,6 +2873,8 @@ class RenderedSST2TestCase(datasets_utils.ImageDatasetTestCase): |
2840 | 2873 | ADDITIONAL_CONFIGS = combinations_grid(split=("train", "val", "test")) |
2841 | 2874 | SPLIT_TO_FOLDER = {"train": "train", "val": "valid", "test": "test"} |
2842 | 2875 |
|
| 2876 | + SUPPORT_TV_IMAGE_DECODE = True |
| 2877 | + |
2843 | 2878 | def inject_fake_data(self, tmpdir: str, config): |
2844 | 2879 | root_folder = pathlib.Path(tmpdir) / "rendered-sst2" |
2845 | 2880 | image_folder = root_folder / self.SPLIT_TO_FOLDER[config["split"]] |
@@ -3500,6 +3535,8 @@ class ImagenetteTestCase(datasets_utils.ImageDatasetTestCase): |
3500 | 3535 | DATASET_CLASS = datasets.Imagenette |
3501 | 3536 | ADDITIONAL_CONFIGS = combinations_grid(split=["train", "val"], size=["full", "320px", "160px"]) |
3502 | 3537 |
|
| 3538 | + SUPPORT_TV_IMAGE_DECODE = True |
| 3539 | + |
3503 | 3540 | _WNIDS = [ |
3504 | 3541 | "n01440764", |
3505 | 3542 | "n02102040", |
|
0 commit comments