Skip to content

Commit 59c1c8b

Browse files
authored
Merge branch 'main' into tests/flaky_stochastic_depth
2 parents b445bfb + 5ea2348 commit 59c1c8b

File tree

9 files changed

+27
-41
lines changed

9 files changed

+27
-41
lines changed

torchvision/prototype/datasets/_builtin/caltech.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,14 @@
2121
OnlineResource,
2222
DatasetType,
2323
)
24-
from torchvision.prototype.datasets.utils._internal import INFINITE_BUFFER_SIZE, BUILTIN_DIR, read_mat
24+
from torchvision.prototype.datasets.utils._internal import INFINITE_BUFFER_SIZE, read_mat
2525

2626

2727
class Caltech101(Dataset):
28-
@property
29-
def info(self) -> DatasetInfo:
28+
def _make_info(self) -> DatasetInfo:
3029
return DatasetInfo(
3130
"caltech101",
3231
type=DatasetType.IMAGE,
33-
categories=BUILTIN_DIR / "caltech101.categories",
3432
homepage="http://www.vision.caltech.edu/Image_Datasets/Caltech101",
3533
)
3634

@@ -144,12 +142,10 @@ def _generate_categories(self, root: pathlib.Path) -> List[str]:
144142

145143

146144
class Caltech256(Dataset):
147-
@property
148-
def info(self) -> DatasetInfo:
145+
def _make_info(self) -> DatasetInfo:
149146
return DatasetInfo(
150147
"caltech256",
151148
type=DatasetType.IMAGE,
152-
categories=BUILTIN_DIR / "caltech256.categories",
153149
homepage="http://www.vision.caltech.edu/Image_Datasets/Caltech256",
154150
)
155151

torchvision/prototype/datasets/_builtin/celeba.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ def __iter__(self) -> Iterator[Tuple[str, Dict[str, str]]]:
5858

5959

6060
class CelebA(Dataset):
61-
@property
62-
def info(self) -> DatasetInfo:
61+
def _make_info(self) -> DatasetInfo:
6362
return DatasetInfo(
6463
"celeba",
6564
type=DatasetType.IMAGE,

torchvision/prototype/datasets/_builtin/cifar.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
)
2626
from torchvision.prototype.datasets.utils._internal import (
2727
INFINITE_BUFFER_SIZE,
28-
BUILTIN_DIR,
2928
image_buffer_from_array,
3029
path_comparator,
3130
)
@@ -110,12 +109,10 @@ def _is_data_file(self, data: Tuple[str, Any], *, config: DatasetConfig) -> bool
110109
path = pathlib.Path(data[0])
111110
return path.name.startswith("data" if config.split == "train" else "test")
112111

113-
@property
114-
def info(self) -> DatasetInfo:
112+
def _make_info(self) -> DatasetInfo:
115113
return DatasetInfo(
116114
"cifar10",
117115
type=DatasetType.RAW,
118-
categories=BUILTIN_DIR / "cifar10.categories",
119116
homepage="https://www.cs.toronto.edu/~kriz/cifar.html",
120117
)
121118

@@ -137,12 +134,10 @@ def _is_data_file(self, data: Tuple[str, Any], *, config: DatasetConfig) -> bool
137134
path = pathlib.Path(data[0])
138135
return path.name == cast(str, config.split)
139136

140-
@property
141-
def info(self) -> DatasetInfo:
137+
def _make_info(self) -> DatasetInfo:
142138
return DatasetInfo(
143139
"cifar100",
144140
type=DatasetType.RAW,
145-
categories=BUILTIN_DIR / "cifar100.categories",
146141
homepage="https://www.cs.toronto.edu/~kriz/cifar.html",
147142
valid_options=dict(
148143
split=("train", "test"),

torchvision/prototype/datasets/_builtin/coco.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@
3535

3636

3737
class Coco(Dataset):
38-
@property
39-
def info(self) -> DatasetInfo:
38+
def _make_info(self) -> DatasetInfo:
4039
return DatasetInfo(
4140
"coco",
4241
type=DatasetType.IMAGE,

torchvision/prototype/datasets/_builtin/imagenet.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525

2626

2727
class ImageNet(Dataset):
28-
@property
29-
def info(self) -> DatasetInfo:
28+
def _make_info(self) -> DatasetInfo:
3029
name = "imagenet"
3130
categories, wnids = zip(*DatasetInfo.read_categories_file(BUILTIN_DIR / f"{name}.categories"))
3231

torchvision/prototype/datasets/_builtin/mnist.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,7 @@ def _make_datapipe(
151151

152152

153153
class MNIST(_MNISTBase):
154-
@property
155-
def info(self) -> DatasetInfo:
154+
def _make_info(self) -> DatasetInfo:
156155
return DatasetInfo(
157156
"mnist",
158157
type=DatasetType.RAW,
@@ -182,8 +181,7 @@ def _files_and_checksums(self, config: DatasetConfig) -> Tuple[Tuple[str, str],
182181

183182

184183
class FashionMNIST(MNIST):
185-
@property
186-
def info(self) -> DatasetInfo:
184+
def _make_info(self) -> DatasetInfo:
187185
return DatasetInfo(
188186
"fashionmnist",
189187
type=DatasetType.RAW,
@@ -215,8 +213,7 @@ def info(self) -> DatasetInfo:
215213

216214

217215
class KMNIST(MNIST):
218-
@property
219-
def info(self) -> DatasetInfo:
216+
def _make_info(self) -> DatasetInfo:
220217
return DatasetInfo(
221218
"kmnist",
222219
type=DatasetType.RAW,
@@ -237,8 +234,7 @@ def info(self) -> DatasetInfo:
237234

238235

239236
class EMNIST(_MNISTBase):
240-
@property
241-
def info(self) -> DatasetInfo:
237+
def _make_info(self) -> DatasetInfo:
242238
return DatasetInfo(
243239
"emnist",
244240
type=DatasetType.RAW,
@@ -335,8 +331,7 @@ def _make_datapipe(
335331

336332

337333
class QMNIST(_MNISTBase):
338-
@property
339-
def info(self) -> DatasetInfo:
334+
def _make_info(self) -> DatasetInfo:
340335
return DatasetInfo(
341336
"qmnist",
342337
type=DatasetType.RAW,

torchvision/prototype/datasets/_builtin/sbd.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
)
2626
from torchvision.prototype.datasets.utils._internal import (
2727
INFINITE_BUFFER_SIZE,
28-
BUILTIN_DIR,
2928
read_mat,
3029
getitem,
3130
path_accessor,
@@ -34,12 +33,10 @@
3433

3534

3635
class SBD(Dataset):
37-
@property
38-
def info(self) -> DatasetInfo:
36+
def _make_info(self) -> DatasetInfo:
3937
return DatasetInfo(
4038
"sbd",
4139
type=DatasetType.IMAGE,
42-
categories=BUILTIN_DIR / "caltech256.categories",
4340
homepage="http://home.bharathh.info/pubs/codes/SBD/download.html",
4441
valid_options=dict(
4542
split=("train", "val", "train_noval"),

torchvision/prototype/datasets/_builtin/voc.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@
3535

3636

3737
class VOC(Dataset):
38-
@property
39-
def info(self) -> DatasetInfo:
38+
def _make_info(self) -> DatasetInfo:
4039
return DatasetInfo(
4140
"voc",
4241
type=DatasetType.IMAGE,

torchvision/prototype/datasets/utils/_dataset.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
sequence_to_str,
1313
)
1414

15-
from ._internal import FrozenBunch, make_repr
15+
from ._internal import FrozenBunch, make_repr, BUILTIN_DIR
1616
from ._resource import OnlineResource
1717

1818

@@ -42,8 +42,9 @@ def __init__(
4242
self.type = DatasetType[type.upper()] if isinstance(type, str) else type
4343

4444
if categories is None:
45-
categories = []
46-
elif isinstance(categories, int):
45+
path = BUILTIN_DIR / f"{self.name}.categories"
46+
categories = path if path.exists() else []
47+
if isinstance(categories, int):
4748
categories = [str(label) for label in range(categories)]
4849
elif isinstance(categories, (str, pathlib.Path)):
4950
path = pathlib.Path(categories).expanduser().resolve()
@@ -112,11 +113,17 @@ def __repr__(self) -> str:
112113

113114

114115
class Dataset(abc.ABC):
115-
@property
116+
def __init__(self) -> None:
117+
self._info = self._make_info()
118+
116119
@abc.abstractmethod
117-
def info(self) -> DatasetInfo:
120+
def _make_info(self) -> DatasetInfo:
118121
pass
119122

123+
@property
124+
def info(self) -> DatasetInfo:
125+
return self._info
126+
120127
@property
121128
def name(self) -> str:
122129
return self.info.name

0 commit comments

Comments
 (0)