3
3
4
4
from PIL import Image
5
5
6
- from .utils import download_and_extract_archive , download_url , verify_str_arg
6
+ from .utils import verify_str_arg
7
7
from .vision import VisionDataset
8
8
9
9
10
10
class StanfordCars (VisionDataset ):
11
- """` Stanford Cars <https://ai.stanford.edu/~jkrause/cars/car_dataset.html>`_ Dataset
11
+ """Stanford Cars Dataset
12
12
13
13
The Cars dataset contains 16,185 images of 196 classes of cars. The data is
14
14
split into 8,144 training images and 8,041 testing images, where each class
15
15
has been split roughly in a 50-50 split
16
16
17
+ The original URL is https://ai.stanford.edu/~jkrause/cars/car_dataset.html, but it is broken.
18
+
17
19
.. note::
18
20
19
21
This class needs `scipy <https://docs.scipy.org/doc/>`_ to load target files from `.mat` format.
@@ -25,9 +27,11 @@ class StanfordCars(VisionDataset):
25
27
and returns a transformed version. E.g, ``transforms.RandomCrop``
26
28
target_transform (callable, optional): A function/transform that takes in the
27
29
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
+ """
31
35
32
36
def __init__ (
33
37
self ,
@@ -57,10 +61,18 @@ def __init__(
57
61
self ._images_base_path = self ._base_folder / "cars_test"
58
62
59
63
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
+ )
61
70
62
71
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
+ )
64
76
65
77
self ._samples = [
66
78
(
@@ -87,33 +99,6 @@ def __getitem__(self, idx: int) -> Tuple[Any, Any]:
87
99
target = self .target_transform (target )
88
100
return pil_image , target
89
101
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
-
117
102
def _check_exists (self ) -> bool :
118
103
if not (self ._base_folder / "devkit" ).is_dir ():
119
104
return False
0 commit comments