thanhqt2002 commited on
Commit
e6ff901
·
verified ·
1 Parent(s): 3fb1c1d

Create dataset.py

Browse files
Files changed (1) hide show
  1. dataset.py +60 -0
dataset.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import datasets
3
+
4
+ class MyDatasetConfig(datasets.BuilderConfig):
5
+ def __init__(self, **kwargs):
6
+ super(MyDatasetConfig, self).__init__(**kwargs)
7
+
8
+ class MyDataset(datasets.GeneratorBasedBuilder):
9
+ BUILDER_CONFIGS = [
10
+ MyDatasetConfig(name="1.0.0", version=datasets.Version("1.0.0"), description="Version 1.0.0"),
11
+ ]
12
+
13
+ def _info(self):
14
+ features = datasets.Features(
15
+ {
16
+ "task_id": datasets.Value("string"),
17
+ "task_query": datasets.Value("string"),
18
+ "task_label": datasets.Value("bool"),
19
+ "task_constraint": datasets.Sequence(
20
+ {
21
+ "object_list": datasets.Sequence(datasets.Value("string")),
22
+ "constraint_name": datasets.Value("string")
23
+ }
24
+ ),
25
+ "objects": datasets.Sequence(datasets.Value("string")),
26
+ "related_task_id": datasets.Value("string"),
27
+ "image_url": datasets.Value("string"),
28
+ "scene_id": datasets.Value("string"),
29
+ }
30
+ )
31
+ return datasets.DatasetInfo(
32
+ description=_DESCRIPTION,
33
+ features=features,
34
+ supervised_keys=None,
35
+ homepage=_HOMEPAGE,
36
+ license=_LICENSE,
37
+ citation=_CITATION,
38
+ )
39
+
40
+ def _split_generators(self, dl_manager):
41
+ data_file = dl_manager.download_and_extract("path_to_your_data_file")
42
+ return [
43
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": data_file}),
44
+ ]
45
+
46
+ def _generate_examples(self, filepath):
47
+ with open(filepath, encoding="utf-8") as f:
48
+ data = json.load(f)
49
+ for scene_id, tasks in data.items():
50
+ for task in tasks:
51
+ yield task["task_id"], {
52
+ "task_id": task["task_id"],
53
+ "task_query": task["task_query"],
54
+ "task_label": task["task_label"],
55
+ "task_constraint": task["task_constraint"],
56
+ "objects": task["objects"],
57
+ "related_task_id": task["related_task_id"],
58
+ "image_url": task["image_url"],
59
+ "scene_id": scene_id,
60
+ }