Skip to content

Commit cfe3d89

Browse files
authored
Merge branch 'main' into main
2 parents 507f85f + 6c10d08 commit cfe3d89

File tree

2 files changed

+22
-43
lines changed

2 files changed

+22
-43
lines changed

test/test_datasets_download.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -327,12 +327,6 @@ def kitti():
327327
)
328328

329329

330-
def stanford_cars():
331-
return itertools.chain.from_iterable(
332-
[collect_urls(datasets.StanfordCars, ROOT, split=split, download=True) for split in ["train", "test"]]
333-
)
334-
335-
336330
def url_parametrization(*dataset_urls_and_ids_fns):
337331
return pytest.mark.parametrize(
338332
"url",
@@ -378,9 +372,9 @@ def test_url_is_accessible(url):
378372
retry(lambda: assert_url_is_accessible(url))
379373

380374

381-
@url_parametrization(
382-
stanford_cars, # https://github.com/pytorch/vision/issues/7545
383-
)
375+
# TODO: if e.g. caltech101 starts failing, remove the pytest.mark.parametrize below and use
376+
# @url_parametrization(caltech101)
377+
@pytest.mark.parametrize("url", ("http://url_that_doesnt_exist.com",)) # here until we actually have a failing dataset
384378
@pytest.mark.xfail
385379
def test_url_is_not_accessible(url):
386380
"""

torchvision/datasets/stanford_cars.py

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,19 @@
33

44
from PIL import Image
55

6-
from .utils import download_and_extract_archive, download_url, verify_str_arg
6+
from .utils import verify_str_arg
77
from .vision import VisionDataset
88

99

1010
class StanfordCars(VisionDataset):
11-
"""`Stanford Cars <https://ai.stanford.edu/~jkrause/cars/car_dataset.html>`_ Dataset
11+
"""Stanford Cars Dataset
1212
1313
The Cars dataset contains 16,185 images of 196 classes of cars. The data is
1414
split into 8,144 training images and 8,041 testing images, where each class
1515
has been split roughly in a 50-50 split
1616
17+
The original URL is https://ai.stanford.edu/~jkrause/cars/car_dataset.html, but it is broken.
18+
1719
.. note::
1820
1921
This class needs `scipy <https://docs.scipy.org/doc/>`_ to load target files from `.mat` format.
@@ -25,9 +27,11 @@ class StanfordCars(VisionDataset):
2527
and returns a transformed version. E.g, ``transforms.RandomCrop``
2628
target_transform (callable, optional): A function/transform that takes in the
2729
target and transforms it.
28-
download (bool, optional): If True, downloads the dataset from the internet and
29-
puts it in root directory. If dataset is already downloaded, it is not
30-
downloaded again."""
30+
download (bool, optional): This parameter exists for backward compatibility but it does not
31+
download the dataset, since the original URL is not available anymore. The dataset
32+
seems to be available on Kaggle so you can try to manually download it using
33+
`these instructions <https://github.com/pytorch/vision/issues/7545#issuecomment-1631441616>`_.
34+
"""
3135

3236
def __init__(
3337
self,
@@ -57,10 +61,18 @@ def __init__(
5761
self._images_base_path = self._base_folder / "cars_test"
5862

5963
if download:
60-
self.download()
64+
raise ValueError(
65+
"The original URL is broken so the StanfordCars dataset is not available for automatic "
66+
"download anymore. You can try to download it manually following "
67+
"https://github.com/pytorch/vision/issues/7545#issuecomment-1631441616, "
68+
"and set download=False to avoid this error."
69+
)
6170

6271
if not self._check_exists():
63-
raise RuntimeError("Dataset not found. You can use download=True to download it")
72+
raise RuntimeError(
73+
"Dataset not found. Try to manually download following the instructions in "
74+
"https://github.com/pytorch/vision/issues/7545#issuecomment-1631441616."
75+
)
6476

6577
self._samples = [
6678
(
@@ -87,33 +99,6 @@ def __getitem__(self, idx: int) -> Tuple[Any, Any]:
8799
target = self.target_transform(target)
88100
return pil_image, target
89101

90-
def download(self) -> None:
91-
if self._check_exists():
92-
return
93-
94-
download_and_extract_archive(
95-
url="https://ai.stanford.edu/~jkrause/cars/car_devkit.tgz",
96-
download_root=str(self._base_folder),
97-
md5="c3b158d763b6e2245038c8ad08e45376",
98-
)
99-
if self._split == "train":
100-
download_and_extract_archive(
101-
url="https://ai.stanford.edu/~jkrause/car196/cars_train.tgz",
102-
download_root=str(self._base_folder),
103-
md5="065e5b463ae28d29e77c1b4b166cfe61",
104-
)
105-
else:
106-
download_and_extract_archive(
107-
url="https://ai.stanford.edu/~jkrause/car196/cars_test.tgz",
108-
download_root=str(self._base_folder),
109-
md5="4ce7ebf6a94d07f1952d94dd34c4d501",
110-
)
111-
download_url(
112-
url="https://ai.stanford.edu/~jkrause/car196/cars_test_annos_withlabels.mat",
113-
root=str(self._base_folder),
114-
md5="b0a2b23655a3edd16d84508592a98d10",
115-
)
116-
117102
def _check_exists(self) -> bool:
118103
if not (self._base_folder / "devkit").is_dir():
119104
return False

0 commit comments

Comments
 (0)