File size: 8,319 Bytes
31ea808 83d0eee 31ea808 495523f 31ea808 0f840bd 31ea808 0bac591 31ea808 000853c 31ea808 6fc135c 31ea808 336cfb9 31ea808 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
import json
import os
import datasets
from datasets.tasks import ImageClassification
logger = datasets.logging.get_logger(__name__)
_CITATION = """"""
_DESCRIPTION = """\
Ornithoscope dataset is the dataset used to train the model for the Ornithoscope project.
"""
_HOMEPAGE = ""
_FOLDERS = [
'iNatv1',
'iNatv2',
'PhotoFeederv1/task_05-01-2021',
'PhotoFeederv1/task_06-01-2021',
'PhotoFeederv1/task_18-01-2021',
'PhotoFeederv1/task_19-01-2021',
'PhotoFeederv1/task_20210205',
'PhotoFeederv1/task_20210217',
'PhotoFeederv1/task_20210227',
'PhotoFeederv1/task_20210228',
'PhotoFeederv1/task_2021-03-01_07',
'PhotoFeederv1/task_2021-03-01_08',
'PhotoFeederv1/task_2021-03-01_09',
'PhotoFeederv1/task_2021-03-01_10',
'PhotoFeederv1/task_2021-03-01_11',
'PhotoFeederv1/task_2021-03-01_12',
'PhotoFeederv1/task_2021-03-01_13',
'PhotoFeederv1/task_2021-03-01_14',
'PhotoFeederv1/task_2021-03-01_15',
'PhotoFeederv1/task_2021-03-01_16',
'PhotoFeederv1/task_2021-03-01_17',
'PhotoFeederv1/task_2021-03-01_18',
'PhotoFeederv1/task_20210409',
'PhotoFeederv1/task_20210411',
'PhotoFeederv1/task_20210412',
'PhotoFeederv1/task_20210413_UPS',
'PhotoFeederv1/task_20210414',
'PhotoFeederv1/task_20210415_UPS',
'PhotoFeederv1/task_20210416_UPS',
'PhotoFeederv1/task_20210417_UPS',
'PhotoFeederv1/task_20210418_UPS',
'PhotoFeederv1/task_20210419_UPS',
'PhotoFeederv1/task_20210420',
'PhotoFeederv1/task_20210523_UPS',
'PhotoFeederv1/task_20210525_UPS',
'PhotoFeederv1/task_20210526_UPS',
'PhotoFeederv1/task_20210611_Lab',
'PhotoFeederv1/task_20210612_1_Lab',
'PhotoFeederv1/task_20210615_Lab',
'PhotoFeederv1/task_20210616_Lab',
'PhotoFeederv1/task_20210623_balacet',
'PhotoFeederv1/task_20210624_balacet',
'PhotoFeederv1/task_20210625_balacet',
'PhotoFeederv1/task_20210705-07_balacet',
'PhotoFeederv1/task_20211008_Moulis',
'PhotoFeederv1/task_2021_11_03-04_cescau4',
'PhotoFeederv1/task_20211109_cescau1',
'PhotoFeederv1/task_20211204_Orlu',
'PhotoFeederv1/task_21-01-2021',
'PhotoFeederv1/task_berggris_dordogne',
'PhotoFeederv1/task_berggris',
'PhotoFeederv1/task_MOIDOM_ODJ',
'PhotoFeederv2/Balacet_session1',
'PhotoFeederv2/Balacet_session4',
'PhotoFeederv2/C1_session1',
'PhotoFeederv2/C1_session3',
'PhotoFeederv2/C1_session4',
'PhotoFeederv2/C4_session1',
'PhotoFeederv2/C4_session4',
'PhotoFeederv2/Francon_session1',
'PhotoFeederv2/Francon_session4',
'PhotoFeederv2/Montpellier_session1',
'PhotoFeederv2/Montpellier_session4',
'PhotoFeederv2/Moulis_session4',
'PhotoFeederv2/Orlu_session4',
]
class OrnithoscopeConfig(datasets.BuilderConfig):
"""BuilderConfig for Ornithoscope."""
def __init__(
self,
train_json: str,
validation_json: str,
test_json: str,
**kwargs
):
"""BuilderConfig for Ornithoscope.
Args:
train_json: path to the json file containing the train annotations.
validation_json: path to the json file containing the validation annotations.
test_json: path to the json file containing the test annotations.
**kwargs: keyword arguments forwarded to super.
"""
super().__init__(version=datasets.Version("1.0.0"), **kwargs)
self.train_json = train_json
self.validation_json = validation_json
self.test_json = test_json
class Ornithoscope(datasets.GeneratorBasedBuilder):
VERSION = datasets.Version("1.0.0")
BUILDER_CONFIGS = [
OrnithoscopeConfig(
name="DS3",
description="The main dataset.",
train_json="sets/DS3_train.json",
validation_json="sets/DS3_val.json",
test_json="sets/DS3_test.json",
),
OrnithoscopeConfig(
name="DS4",
description="The new dataset.",
train_json="sets/DS4_train.json",
validation_json="sets/DS4_val.json",
test_json="sets/DS4_test.json",
),
]
def _info(self) -> datasets.DatasetInfo:
return datasets.DatasetInfo(
description=_DESCRIPTION,
# features=datasets.Features(
# {
# "id_path": datasets.Value("string"),
# "path": datasets.Value("string"),
# "boxes": datasets.Sequence(
# {
# "label": datasets.Value("string"),
# "xmin": datasets.Value("float32"),
# "xmax": datasets.Value("float32"),
# "ymin": datasets.Value("float32"),
# "ymax": datasets.Value("float32"),
# }
# ),
# "size": {
# "width": datasets.Value("int32"),
# "height": datasets.Value("int32"),
# },
# },
# ),
homepage=_HOMEPAGE,
citation=_CITATION,
)
def _split_generators(self, dl_manager: datasets.DownloadManager) -> list[datasets.SplitGenerator]:
"""Returns SplitGenerators."""
archives = self._get_archives(dl_manager)
# Get train paths.
train_json = json.load(
open(dl_manager.download_and_extract(self.config.train_json), 'r'))
train_vals = []
for id_path, value in train_json.items():
root, file = os.path.split(id_path)
path = os.path.join(archives[root], file)
val = {
"id_path": id_path,
"path": path,
"boxes": value['boxes'],
"size": value['size'],
}
train_vals.append(val)
# Get validation paths.
validation_json = json.load(
open(dl_manager.download_and_extract(self.config.validation_json), 'r'))
validation_vals = []
for id_path, value in validation_json.items():
root, file = os.path.split(id_path)
path = os.path.join(archives[root], file)
val = {
"id_path": id_path,
"path": path,
"boxes": value['boxes'],
"size": value['size'],
}
validation_vals.append(val)
# Get test paths.
test_json = json.load(
open(dl_manager.download_and_extract(self.config.test_json), 'r'))
test_vals = []
for id_path, value in test_json.items():
root, file = os.path.split(id_path)
path = os.path.join(archives[root], file)
val = {
"id_path": id_path,
"path": path,
"boxes": value['boxes'],
"size": value['size'],
}
test_vals.append(val)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"values": train_vals,
},
),
datasets.SplitGenerator(
name=datasets.Split.VALIDATION,
gen_kwargs={
"values": validation_vals,
},
),
datasets.SplitGenerator(
name=datasets.Split.TEST,
gen_kwargs={
"values": test_vals,
},
),
]
def _generate_examples(self, values: list) -> tuple:
"""Yields examples."""
idx = 0
for val in values:
example = {
"id_path": val["id_path"],
"path": val["path"],
"boxes": val["boxes"],
"size": val["size"],
}
yield idx, example
idx += 1
def _get_archives(self, dl_manager: datasets.DownloadManager) -> dict:
"""Get the archives containing the images."""
archives = {}
for folder in _FOLDERS:
archives[folder] = dl_manager.download_and_extract(
f'data/{folder}.tar'
)
return archives
|