Nibir commited on
Commit
aabb49d
·
verified ·
1 Parent(s): c814e55

Update dataset.py

Browse files
Files changed (1) hide show
  1. dataset.py +17 -15
dataset.py CHANGED
@@ -1,12 +1,13 @@
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"),
@@ -17,35 +18,36 @@ class IrrisightDataset(GeneratorBasedBuilder):
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
- }
 
1
  import json
2
  import os
3
+ from datasets import DatasetInfo, GeneratorBasedBuilder, Split, SplitGenerator, Features, Value
4
 
 
5
 
6
  class IrrisightDataset(GeneratorBasedBuilder):
7
+ VERSION = "1.0.0"
8
+
9
+ def _info(self):
10
+ return DatasetInfo(
11
  description="IRRISIGHT dataset with compressed tar.gz archives",
12
  features=Features({
13
  "image_path": Value("string"),
 
18
  "split": Value("string")
19
  }),
20
  )
 
21
 
22
  def _split_generators(self, dl_manager):
23
+ downloaded = dl_manager.download_and_extract({
24
+ "tar": "https://huggingface.co/datasets/Nibir/IRRISIGHT/resolve/main/Data/New%20Jersey/2023.tar.gz",
25
+ "meta": "https://huggingface.co/datasets/Nibir/IRRISIGHT/resolve/main/Data/New%20Jersey/metadata.jsonl"
 
 
26
  })
27
 
28
  return [
29
  SplitGenerator(
30
  name=Split.TRAIN,
31
  gen_kwargs={
32
+ "metadata_path": downloaded["meta"],
33
+ "unzipped_dir": downloaded["tar"]
34
  }
35
  )
36
  ]
37
 
38
+ def _generate_examples(self, metadata_path, unzipped_dir):
39
  with open(metadata_path, "r") as f:
40
  for idx, line in enumerate(f):
41
  record = json.loads(line)
42
+
43
+ # Full absolute path to image folder (uncompressed patch dir)
44
+ image_path = os.path.join(unzipped_dir, record["image_path"])
45
+
46
  yield idx, {
47
+ "image_path": image_path,
48
  "label_type": record.get("label_type", ""),
49
  "text_prompt": record.get("text_prompt", ""),
50
  "polygon": record.get("polygon", ""),
51
  "crs": record.get("crs", ""),
52
  "split": record.get("split", "")
53
+ }