33
44from PIL import Image
55
6- from .utils import download_and_extract_archive , download_url , verify_str_arg
6+ from .utils import verify_str_arg
77from .vision import VisionDataset
88
99
1010class 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