Datasets:
Create dataset.py
Browse files- dataset.py +51 -0
dataset.py
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
import os
|
3 |
+
import tarfile
|
4 |
+
|
5 |
+
from datasets import DatasetInfo, GeneratorBasedBuilder, Split, SplitGenerator, Value, Features
|
6 |
+
|
7 |
+
class IrrisightDataset(GeneratorBasedBuilder):
|
8 |
+
BUILDER_CONFIGS = [
|
9 |
+
DatasetInfo(
|
10 |
+
description="IRRISIGHT dataset with compressed tar.gz archives",
|
11 |
+
features=Features({
|
12 |
+
"image_path": Value("string"),
|
13 |
+
"label_type": Value("string"),
|
14 |
+
"text_prompt": Value("string"),
|
15 |
+
"polygon": Value("string"),
|
16 |
+
"crs": Value("string"),
|
17 |
+
"split": Value("string")
|
18 |
+
}),
|
19 |
+
)
|
20 |
+
]
|
21 |
+
|
22 |
+
def _split_generators(self, dl_manager):
|
23 |
+
root_dir = dl_manager.download_and_extract({
|
24 |
+
"maryland": {
|
25 |
+
"data": "https://huggingface.co/datasets/Nibir/IRRISIGHT/resolve/main/New Jersey/2023.tar.gz",
|
26 |
+
"meta": "https://huggingface.co/datasets/Nibir/IRRISIGHT/resolve/main/New Jersey/metadata.jsonl"
|
27 |
+
}
|
28 |
+
})
|
29 |
+
|
30 |
+
return [
|
31 |
+
SplitGenerator(
|
32 |
+
name=Split.TRAIN,
|
33 |
+
gen_kwargs={
|
34 |
+
"metadata_path": root_dir["maryland"]["meta"],
|
35 |
+
"image_dir": os.path.join(root_dir["maryland"]["data"], "2023")
|
36 |
+
}
|
37 |
+
)
|
38 |
+
]
|
39 |
+
|
40 |
+
def _generate_examples(self, metadata_path, image_dir):
|
41 |
+
with open(metadata_path, "r") as f:
|
42 |
+
for idx, line in enumerate(f):
|
43 |
+
record = json.loads(line)
|
44 |
+
yield idx, {
|
45 |
+
"image_path": os.path.join(image_dir, os.path.basename(record["image_path"])),
|
46 |
+
"label_type": record.get("label_type", ""),
|
47 |
+
"text_prompt": record.get("text_prompt", ""),
|
48 |
+
"polygon": record.get("polygon", ""),
|
49 |
+
"crs": record.get("crs", ""),
|
50 |
+
"split": record.get("split", "")
|
51 |
+
}
|