|
3 | 3 | from collections import namedtuple
|
4 | 4 | import zipfile
|
5 | 5 |
|
6 |
| -from .utils import extract_archive |
| 6 | +from .utils import extract_archive, verify_str_arg, iterable_to_str |
7 | 7 | from .vision import VisionDataset
|
8 | 8 | from PIL import Image
|
9 | 9 |
|
@@ -109,22 +109,21 @@ def __init__(self, root, split='train', mode='fine', target_type='instance',
|
109 | 109 | self.images = []
|
110 | 110 | self.targets = []
|
111 | 111 |
|
112 |
| - if mode not in ['fine', 'coarse']: |
113 |
| - raise ValueError('Invalid mode! Please use mode="fine" or mode="coarse"') |
114 |
| - |
115 |
| - if mode == 'fine' and split not in ['train', 'test', 'val']: |
116 |
| - raise ValueError('Invalid split for mode "fine"! Please use split="train", split="test"' |
117 |
| - ' or split="val"') |
118 |
| - elif mode == 'coarse' and split not in ['train', 'train_extra', 'val']: |
119 |
| - raise ValueError('Invalid split for mode "coarse"! Please use split="train", split="train_extra"' |
120 |
| - ' or split="val"') |
| 112 | + verify_str_arg(mode, "mode", ("fine", "coarse")) |
| 113 | + if mode == "fine": |
| 114 | + valid_modes = ("train", "test", "val") |
| 115 | + else: |
| 116 | + valid_modes = ("train", "train_extra", "val") |
| 117 | + msg = ("Unknown value '{}' for argument split if mode is '{}'. " |
| 118 | + "Valid values are {{{}}}.") |
| 119 | + msg = msg.format(split, mode, iterable_to_str(valid_modes)) |
| 120 | + verify_str_arg(split, "split", valid_modes, msg) |
121 | 121 |
|
122 | 122 | if not isinstance(target_type, list):
|
123 | 123 | self.target_type = [target_type]
|
124 |
| - |
125 |
| - if not all(t in ['instance', 'semantic', 'polygon', 'color'] for t in self.target_type): |
126 |
| - raise ValueError('Invalid value for "target_type"! Valid values are: "instance", "semantic", "polygon"' |
127 |
| - ' or "color"') |
| 124 | + [verify_str_arg(value, "target_type", |
| 125 | + ("instance", "semantic", "polygon", "color")) |
| 126 | + for value in self.target_type] |
128 | 127 |
|
129 | 128 | if not os.path.isdir(self.images_dir) or not os.path.isdir(self.targets_dir):
|
130 | 129 |
|
|
0 commit comments