File size: 2,006 Bytes
8f999bc
 
aabb49d
8f999bc
 
 
aabb49d
 
 
 
8f999bc
 
 
 
 
 
 
 
 
 
 
 
aabb49d
 
 
8f999bc
 
2eb0109
 
8f999bc
 
 
 
aabb49d
 
8f999bc
 
 
 
aabb49d
8f999bc
 
 
aabb49d
 
 
 
8f999bc
aabb49d
8f999bc
 
 
 
 
aabb49d
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
import json
import os
from datasets import DatasetInfo, GeneratorBasedBuilder, Split, SplitGenerator, Features, Value


class IrrisightDataset(GeneratorBasedBuilder):
    VERSION = "1.0.0"

    def _info(self):
        return DatasetInfo(
            description="IRRISIGHT dataset with compressed tar.gz archives",
            features=Features({
                "image_path": Value("string"),
                "label_type": Value("string"),
                "text_prompt": Value("string"),
                "polygon": Value("string"),
                "crs": Value("string"),
                "split": Value("string")
            }),
        )

    def _split_generators(self, dl_manager):
        downloaded = dl_manager.download_and_extract({
            "tar": "https://huggingface.co/datasets/Nibir/IRRISIGHT/resolve/main/Data/New%20Jersey/2023.tar.gz",
            "meta": "https://huggingface.co/datasets/Nibir/IRRISIGHT/resolve/main/Data/New%20Jersey/metadata.jsonl"
        })

        print(downloaded)

        return [
            SplitGenerator(
                name=Split.TRAIN,
                gen_kwargs={
                    "metadata_path": downloaded["meta"],
                    "unzipped_dir": downloaded["tar"]
                }
            )
        ]

    def _generate_examples(self, metadata_path, unzipped_dir):
        with open(metadata_path, "r") as f:
            for idx, line in enumerate(f):
                record = json.loads(line)

                # Full absolute path to image folder (uncompressed patch dir)
                image_path = os.path.join(unzipped_dir, record["image_path"])

                yield idx, {
                    "image_path": image_path,
                    "label_type": record.get("label_type", ""),
                    "text_prompt": record.get("text_prompt", ""),
                    "polygon": record.get("polygon", ""),
                    "crs": record.get("crs", ""),
                    "split": record.get("split", "")
                }