Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
vision
Commits
6c10d080
Unverified
Commit
6c10d080
authored
Mar 13, 2024
by
Nicolas Hug
Committed by
GitHub
Mar 13, 2024
Browse files
Disable download for StanfordCars dataset (#8309)
parent
423a1b0e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
43 deletions
+22
-43
test/test_datasets_download.py
test/test_datasets_download.py
+3
-9
torchvision/datasets/stanford_cars.py
torchvision/datasets/stanford_cars.py
+19
-34
No files found.
test/test_datasets_download.py
View file @
6c10d080
...
@@ -327,12 +327,6 @@ def kitti():
...
@@ -327,12 +327,6 @@ def kitti():
)
)
def
stanford_cars
():
return
itertools
.
chain
.
from_iterable
(
[
collect_urls
(
datasets
.
StanfordCars
,
ROOT
,
split
=
split
,
download
=
True
)
for
split
in
[
"train"
,
"test"
]]
)
def
url_parametrization
(
*
dataset_urls_and_ids_fns
):
def
url_parametrization
(
*
dataset_urls_and_ids_fns
):
return
pytest
.
mark
.
parametrize
(
return
pytest
.
mark
.
parametrize
(
"url"
,
"url"
,
...
@@ -378,9 +372,9 @@ def test_url_is_accessible(url):
...
@@ -378,9 +372,9 @@ def test_url_is_accessible(url):
retry
(
lambda
:
assert_url_is_accessible
(
url
))
retry
(
lambda
:
assert_url_is_accessible
(
url
))
@
url_parametrization
(
# TODO: if e.g. caltech101 starts failing, remove the pytest.mark.parametrize below and use
stanford_cars
,
# https://github.com/pytorch/vision/issues/7545
# @url_parametrization(caltech101)
)
@
pytest
.
mark
.
parametrize
(
"url"
,
(
"http://url_that_doesnt_exist.com"
,))
# here until we actually have a failing dataset
@
pytest
.
mark
.
xfail
@
pytest
.
mark
.
xfail
def
test_url_is_not_accessible
(
url
):
def
test_url_is_not_accessible
(
url
):
"""
"""
...
...
torchvision/datasets/stanford_cars.py
View file @
6c10d080
...
@@ -3,17 +3,19 @@ from typing import Any, Callable, Optional, Tuple
...
@@ -3,17 +3,19 @@ from typing import Any, Callable, Optional, Tuple
from
PIL
import
Image
from
PIL
import
Image
from
.utils
import
download_and_extract_archive
,
download_url
,
verify_str_arg
from
.utils
import
verify_str_arg
from
.vision
import
VisionDataset
from
.vision
import
VisionDataset
class
StanfordCars
(
VisionDataset
):
class
StanfordCars
(
VisionDataset
):
"""
`
Stanford Cars
<https://ai.stanford.edu/~jkrause/cars/car_dataset.html>`_
Dataset
"""Stanford Cars Dataset
The Cars dataset contains 16,185 images of 196 classes of cars. The data is
The Cars dataset contains 16,185 images of 196 classes of cars. The data is
split into 8,144 training images and 8,041 testing images, where each class
split into 8,144 training images and 8,041 testing images, where each class
has been split roughly in a 50-50 split
has been split roughly in a 50-50 split
The original URL is https://ai.stanford.edu/~jkrause/cars/car_dataset.html, but it is broken.
.. note::
.. note::
This class needs `scipy <https://docs.scipy.org/doc/>`_ to load target files from `.mat` format.
This class needs `scipy <https://docs.scipy.org/doc/>`_ to load target files from `.mat` format.
...
@@ -25,9 +27,11 @@ class StanfordCars(VisionDataset):
...
@@ -25,9 +27,11 @@ class StanfordCars(VisionDataset):
and returns a transformed version. E.g, ``transforms.RandomCrop``
and returns a transformed version. E.g, ``transforms.RandomCrop``
target_transform (callable, optional): A function/transform that takes in the
target_transform (callable, optional): A function/transform that takes in the
target and transforms it.
target and transforms it.
download (bool, optional): If True, downloads the dataset from the internet and
download (bool, optional): This parameter exists for backward compatibility but it does not
puts it in root directory. If dataset is already downloaded, it is not
download the dataset, since the original URL is not available anymore. The dataset
downloaded again."""
seems to be available on Kaggle so you can try to manually download it using
`these instructions <https://github.com/pytorch/vision/issues/7545#issuecomment-1631441616>`_.
"""
def
__init__
(
def
__init__
(
self
,
self
,
...
@@ -57,10 +61,18 @@ class StanfordCars(VisionDataset):
...
@@ -57,10 +61,18 @@ class StanfordCars(VisionDataset):
self
.
_images_base_path
=
self
.
_base_folder
/
"cars_test"
self
.
_images_base_path
=
self
.
_base_folder
/
"cars_test"
if
download
:
if
download
:
self
.
download
()
raise
ValueError
(
"The original URL is broken so the StanfordCars dataset is not available for automatic "
"download anymore. You can try to download it manually following "
"https://github.com/pytorch/vision/issues/7545#issuecomment-1631441616, "
"and set download=False to avoid this error."
)
if
not
self
.
_check_exists
():
if
not
self
.
_check_exists
():
raise
RuntimeError
(
"Dataset not found. You can use download=True to download it"
)
raise
RuntimeError
(
"Dataset not found. Try to manually download following the instructions in "
"https://github.com/pytorch/vision/issues/7545#issuecomment-1631441616."
)
self
.
_samples
=
[
self
.
_samples
=
[
(
(
...
@@ -87,33 +99,6 @@ class StanfordCars(VisionDataset):
...
@@ -87,33 +99,6 @@ class StanfordCars(VisionDataset):
target
=
self
.
target_transform
(
target
)
target
=
self
.
target_transform
(
target
)
return
pil_image
,
target
return
pil_image
,
target
def
download
(
self
)
->
None
:
if
self
.
_check_exists
():
return
download_and_extract_archive
(
url
=
"https://ai.stanford.edu/~jkrause/cars/car_devkit.tgz"
,
download_root
=
str
(
self
.
_base_folder
),
md5
=
"c3b158d763b6e2245038c8ad08e45376"
,
)
if
self
.
_split
==
"train"
:
download_and_extract_archive
(
url
=
"https://ai.stanford.edu/~jkrause/car196/cars_train.tgz"
,
download_root
=
str
(
self
.
_base_folder
),
md5
=
"065e5b463ae28d29e77c1b4b166cfe61"
,
)
else
:
download_and_extract_archive
(
url
=
"https://ai.stanford.edu/~jkrause/car196/cars_test.tgz"
,
download_root
=
str
(
self
.
_base_folder
),
md5
=
"4ce7ebf6a94d07f1952d94dd34c4d501"
,
)
download_url
(
url
=
"https://ai.stanford.edu/~jkrause/car196/cars_test_annos_withlabels.mat"
,
root
=
str
(
self
.
_base_folder
),
md5
=
"b0a2b23655a3edd16d84508592a98d10"
,
)
def
_check_exists
(
self
)
->
bool
:
def
_check_exists
(
self
)
->
bool
:
if
not
(
self
.
_base_folder
/
"devkit"
).
is_dir
():
if
not
(
self
.
_base_folder
/
"devkit"
).
is_dir
():
return
False
return
False
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment