Datasets:
BSD100

Task Categories: other
Multilinguality: monolingual
Size Categories: unknown
Language Creators: found
Annotations Creators: machine-generated
Source Datasets: original
BSD100 / BSD100.py
Eugene Siow
Add data. 600666e
1 # coding=utf-8
2 # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 """BSD100 dataset: An evaluation dataset for the image super resolution task"""
16
17
18 import datasets
19 from pathlib import Path
20
21
22 _CITATION = """
23 @inproceedings{martin2001database,
24 title={A database of human segmented natural images and its application to evaluating segmentation algorithms and measuring ecological statistics},
25 author={Martin, David and Fowlkes, Charless and Tal, Doron and Malik, Jitendra},
26 booktitle={Proceedings Eighth IEEE International Conference on Computer Vision. ICCV 2001},
27 volume={2},
28 pages={416--423},
29 year={2001},
30 organization={IEEE}
31 }
32 """
33
34 _DESCRIPTION = """
35 BSD is a dataset used frequently for image denoising and super-resolution.
36 BSD100 is the testing set of the Berkeley segmentation dataset BSD300.
37 """
38
39 _HOMEPAGE = "https://www2.eecs.berkeley.edu/Research/Projects/CS/vision/bsds/"
40
41 _LICENSE = "UNK"
42
43 _DL_URL = "https://huggingface.co/datasets/eugenesiow/BSD100/resolve/main/data/"
44
45 _DEFAULT_CONFIG = "bicubic_x2"
46
47 _DATA_OPTIONS = {
48 "bicubic_x2": {
49 "hr": _DL_URL + "BSD100_HR.tar.gz",
50 "lr": _DL_URL + "BSD100_LR_x2.tar.gz",
51 },
52 "bicubic_x3": {
53 "hr": _DL_URL + "BSD100_HR.tar.gz",
54 "lr": _DL_URL + "BSD100_LR_x3.tar.gz",
55 },
56 "bicubic_x4": {
57 "hr": _DL_URL + "BSD100_HR.tar.gz",
58 "lr": _DL_URL + "BSD100_LR_x4.tar.gz",
59 }
60 }
61
62
63 class Bsd100Config(datasets.BuilderConfig):
64 """BuilderConfig for BSD100."""
65
66 def __init__(
67 self,
68 name,
69 hr_url,
70 lr_url,
71 **kwargs,
72 ):
73 if name not in _DATA_OPTIONS:
74 raise ValueError("data must be one of %s" % _DATA_OPTIONS)
75 super(Bsd100Config, self).__init__(name=name, version=datasets.Version("1.0.0"), **kwargs)
76 self.hr_url = hr_url
77 self.lr_url = lr_url
78
79
80 class Bsd100(datasets.GeneratorBasedBuilder):
81 """BSD100 dataset for single image super resolution evaluation."""
82
83 BUILDER_CONFIGS = [
84 Bsd100Config(
85 name=key,
86 hr_url=values['hr'],
87 lr_url=values['lr']
88 ) for key, values in _DATA_OPTIONS.items()
89 ]
90
91 DEFAULT_CONFIG_NAME = _DEFAULT_CONFIG
92
93 def _info(self):
94 features = datasets.Features(
95 {
96 "hr": datasets.Value("string"),
97 "lr": datasets.Value("string"),
98 }
99 )
100 return datasets.DatasetInfo(
101 description=_DESCRIPTION,
102 features=features,
103 supervised_keys=None,
104 homepage=_HOMEPAGE,
105 license=_LICENSE,
106 citation=_CITATION,
107 )
108
109 def _split_generators(self, dl_manager):
110 """Returns SplitGenerators."""
111 hr_data_dir = dl_manager.download_and_extract(self.config.hr_url)
112 lr_data_dir = dl_manager.download_and_extract(self.config.lr_url)
113 return [
114 datasets.SplitGenerator(
115 name=datasets.Split.VALIDATION,
116 # These kwargs will be passed to _generate_examples
117 gen_kwargs={
118 "lr_path": lr_data_dir,
119 "hr_path": str(Path(hr_data_dir) / 'BSD100_HR')
120 },
121 )
122 ]
123
124 def _generate_examples(
125 self, hr_path, lr_path
126 ):
127 """ Yields examples as (key, example) tuples. """
128 # This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
129 # The `key` is here for legacy reason (tfds) and is not important in itself.
130 extensions = {'.png'}
131 for file_path in sorted(Path(lr_path).glob("**/*")):
132 if file_path.suffix in extensions:
133 file_path_str = str(file_path.as_posix())
134 yield file_path_str, {
135 'lr': file_path_str,
136 'hr': str((Path(hr_path) / file_path.name).as_posix())
137 }
138