Skip to content

Commit b0be39d

Browse files
committed
revert enum usage for single use constants
1 parent 0488e71 commit b0be39d

File tree

5 files changed

+12
-46
lines changed

5 files changed

+12
-46
lines changed

torchvision/prototype/datasets/_builtin/clevr.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import enum
21
import functools
32
import io
43
import pathlib
@@ -25,11 +24,6 @@
2524
from torchvision.prototype.features import Label
2625

2726

28-
class CLEVRDemux(enum.IntEnum):
29-
IMAGES = 0
30-
SCENES = 1
31-
32-
3327
class CLEVR(Dataset):
3428
def _make_info(self) -> DatasetInfo:
3529
return DatasetInfo(
@@ -49,9 +43,9 @@ def resources(self, config: DatasetConfig) -> List[OnlineResource]:
4943
def _classify_archive(self, data: Tuple[str, Any]) -> Optional[int]:
5044
path = pathlib.Path(data[0])
5145
if path.parents[1].name == "images":
52-
return CLEVRDemux.IMAGES
46+
return 0
5347
elif path.parent.name == "scenes":
54-
return CLEVRDemux.SCENES
48+
return 1
5549
else:
5650
return None
5751

torchvision/prototype/datasets/_builtin/coco.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import enum
21
import functools
32
import io
43
import pathlib
@@ -38,11 +37,6 @@
3837
from torchvision.prototype.utils._internal import FrozenMapping
3938

4039

41-
class CocoDemux(enum.IntEnum):
42-
IMAGES_META = 0
43-
ANNS_META = 1
44-
45-
4640
class Coco(Dataset):
4741
def _make_info(self) -> DatasetInfo:
4842
name = "coco"
@@ -150,9 +144,9 @@ def _filter_meta_files(self, data: Tuple[str, Any], *, split: str, year: str, an
150144
def _classify_meta(self, data: Tuple[str, Any]) -> Optional[int]:
151145
key, _ = data
152146
if key == "images":
153-
return CocoDemux.IMAGES_META
147+
return 0
154148
elif key == "annotations":
155-
return CocoDemux.ANNS_META
149+
return 1
156150
else:
157151
return None
158152

torchvision/prototype/datasets/_builtin/mnist.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import abc
2-
import enum
32
import functools
43
import io
54
import operator
@@ -233,11 +232,6 @@ def _make_info(self) -> DatasetInfo:
233232
}
234233

235234

236-
class EMNISTDemux(enum.IntEnum):
237-
IMAGES = 0
238-
LABELS = 1
239-
240-
241235
class EMNIST(_MNISTBase):
242236
def _make_info(self) -> DatasetInfo:
243237
return DatasetInfo(
@@ -279,9 +273,9 @@ def _classify_archive(self, data: Tuple[str, Any], *, config: DatasetConfig) ->
279273
path = pathlib.Path(data[0])
280274
(images_file, _), (labels_file, _) = self._files_and_checksums(config)
281275
if path.name == images_file:
282-
return EMNISTDemux.IMAGES
276+
return 0
283277
elif path.name == labels_file:
284-
return EMNISTDemux.LABELS
278+
return 1
285279
else:
286280
return None
287281

@@ -326,7 +320,6 @@ def _make_datapipe(
326320
decoder: Optional[Callable[[io.IOBase], torch.Tensor]],
327321
) -> IterDataPipe[Dict[str, Any]]:
328322
archive_dp = resource_dps[0]
329-
330323
images_dp, labels_dp = Demultiplexer(
331324
archive_dp,
332325
2,

torchvision/prototype/datasets/_builtin/sbd.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import enum
21
import functools
32
import io
43
import pathlib
@@ -34,12 +33,6 @@
3433
)
3534

3635

37-
class SBDDemux(enum.IntEnum):
38-
SPLIT = 0
39-
IMAGES = 1
40-
ANNS = 2
41-
42-
4336
class SBD(Dataset):
4437
def _make_info(self) -> DatasetInfo:
4538
return DatasetInfo(
@@ -70,12 +63,12 @@ def _classify_archive(self, data: Tuple[str, Any]) -> Optional[int]:
7063
parent, grandparent, *_ = path.parents
7164

7265
if parent.name == "dataset":
73-
return SBDDemux.SPLIT
66+
return 0
7467
elif grandparent.name == "dataset":
7568
if parent.name == "img":
76-
return SBDDemux.IMAGES
69+
return 1
7770
elif parent.name == "cls":
78-
return SBDDemux.ANNS
71+
return 2
7972
else:
8073
return None
8174
else:

torchvision/prototype/datasets/_builtin/voc.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import enum
21
import functools
32
import io
43
import pathlib
@@ -32,13 +31,6 @@
3231
hint_shuffling,
3332
)
3433

35-
36-
class VOCDemux(enum.IntEnum):
37-
SPLIT = 0
38-
IMAGES = 1
39-
ANNS = 2
40-
41-
4234
HERE = pathlib.Path(__file__).parent
4335

4436

@@ -83,11 +75,11 @@ def _is_in_folder(self, data: Tuple[str, Any], *, name: str, depth: int = 1) ->
8375

8476
def _classify_archive(self, data: Tuple[str, Any], *, config: DatasetConfig) -> Optional[int]:
8577
if self._is_in_folder(data, name="ImageSets", depth=2):
86-
return VOCDemux.SPLIT
78+
return 0
8779
elif self._is_in_folder(data, name="JPEGImages"):
88-
return VOCDemux.IMAGES
80+
return 1
8981
elif self._is_in_folder(data, name=self._ANNS_FOLDER[config.task]):
90-
return VOCDemux.ANNS
82+
return 2
9183
else:
9284
return None
9385

0 commit comments

Comments
 (0)