Datasets:

Languages:
English
ArXiv:
License:
JasiLiang commited on
Commit
bd5e3cb
·
verified ·
1 Parent(s): 495e5e5

Upload dataset_script.py

Browse files
Files changed (1) hide show
  1. dataset_script.py +64 -0
dataset_script.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import json
3
+ import datasets
4
+ from datasets import Dataset, DatasetInfo, SplitGenerator, Value, Features
5
+ from pathlib import Path
6
+
7
+ class MyGenerationDataset(datasets.GeneratorBasedBuilder):
8
+ def _info(self):
9
+ return DatasetInfo(
10
+ description="IDEA-Bench.",
11
+ features=Features({
12
+ "task name": Value('string'),
13
+ "task ID": Value('string'),
14
+ "case ID": Value('string'),
15
+ "images": datasets.Sequence(datasets.Image()),
16
+ "instruction": Value('string'),
17
+ }),
18
+ license="cc-by-nc-4.0",
19
+ )
20
+
21
+ def _split_generators(self, dl_manager):
22
+ data_dir = './'
23
+ return [
24
+ SplitGenerator(name=datasets.Split.TEST, gen_kwargs={'data_dir': data_dir}),
25
+ ]
26
+
27
+ def _generate_examples(self, data_dir):
28
+ for folder_name in os.listdir(data_dir):
29
+ folder_path = os.path.join(data_dir, folder_name)
30
+ if os.path.isdir(folder_path):
31
+ meta_path = os.path.join(folder_path, 'meta.json')
32
+ if not os.path.exists(meta_path):
33
+ continue
34
+
35
+ with open(meta_path, 'r', encoding='utf-8') as f:
36
+ meta_data = json.load(f)
37
+
38
+ task_name = meta_data.get("task_name", "")
39
+ uid = meta_data.get("uid", "")
40
+ case_id = meta_data.get("case_id", "")
41
+
42
+ instruction_path = os.path.join(folder_path, 'instruction.txt')
43
+ with open(instruction_path, 'r', encoding='utf-8') as f:
44
+ instruction = f.read().strip()
45
+
46
+ image_files = [f for f in os.listdir(folder_path) if f.endswith('.jpg')]
47
+
48
+ if not image_files:
49
+ yield folder_name, {
50
+ 'task name': task_name,
51
+ 'task ID': uid,
52
+ 'case ID': case_id,
53
+ 'image': [],
54
+ 'instruction': instruction,
55
+ }
56
+ else:
57
+ image_paths = [os.path.join(folder_path, img_file) for img_file in image_files]
58
+ yield folder_name, {
59
+ 'task name': task_name,
60
+ 'task ID': uid,
61
+ 'case ID': case_id,
62
+ 'images': image_paths,
63
+ 'instruction': instruction,
64
+ }