fix loader
Browse files- maplm_v2.py +38 -19
maplm_v2.py
CHANGED
|
@@ -21,6 +21,7 @@ _CITATION = """\
|
|
| 21 |
}
|
| 22 |
"""
|
| 23 |
|
|
|
|
| 24 |
class MapLMBuilderConfig(datasets.BuilderConfig):
|
| 25 |
"""BuilderConfig for MapLM dataset."""
|
| 26 |
|
|
@@ -30,7 +31,6 @@ class MapLMBuilderConfig(datasets.BuilderConfig):
|
|
| 30 |
|
| 31 |
|
| 32 |
class MapLMDataset(datasets.GeneratorBasedBuilder):
|
| 33 |
-
|
| 34 |
BUILDER_CONFIG_CLASS = MapLMBuilderConfig
|
| 35 |
BUILDER_CONFIGS = [
|
| 36 |
MapLMBuilderConfig(
|
|
@@ -47,7 +47,7 @@ class MapLMDataset(datasets.GeneratorBasedBuilder):
|
|
| 47 |
"images": datasets.Sequence(datasets.Value("string")),
|
| 48 |
"question": datasets.Sequence(datasets.Value("string")),
|
| 49 |
"options": datasets.Sequence(datasets.Sequence(datasets.Value("string"))),
|
| 50 |
-
"answer": datasets.Sequence(datasets.Value("string")),
|
| 51 |
"tag": datasets.Sequence(datasets.Value("string")),
|
| 52 |
}
|
| 53 |
|
|
@@ -65,7 +65,7 @@ class MapLMDataset(datasets.GeneratorBasedBuilder):
|
|
| 65 |
splits = []
|
| 66 |
data_root = dl_manager.download("data/")
|
| 67 |
for split in self.config.splits:
|
| 68 |
-
annotation_file = os.path.join(data_root,
|
| 69 |
annotations = json.load(open(annotation_file))
|
| 70 |
if split == "test":
|
| 71 |
generator = datasets.SplitGenerator(
|
|
@@ -91,26 +91,45 @@ class MapLMDataset(datasets.GeneratorBasedBuilder):
|
|
| 91 |
def _generate_examples(self, annotations):
|
| 92 |
for i, anno_key in enumerate(annotations):
|
| 93 |
data_item = {}
|
| 94 |
-
data_item["frame_id"] = annotations[anno_key]["
|
| 95 |
-
data_item["images"] = annotations[anno_key]["
|
| 96 |
data_item["question"] = []
|
| 97 |
data_item["options"] = []
|
| 98 |
data_item["answer"] = []
|
| 99 |
data_item["tag"] = []
|
| 100 |
for perception_key in annotations[anno_key]["QA"]["perception"]:
|
| 101 |
-
data_item["question"].append(
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
|
| 116 |
-
|
|
|
|
| 21 |
}
|
| 22 |
"""
|
| 23 |
|
| 24 |
+
|
| 25 |
class MapLMBuilderConfig(datasets.BuilderConfig):
|
| 26 |
"""BuilderConfig for MapLM dataset."""
|
| 27 |
|
|
|
|
| 31 |
|
| 32 |
|
| 33 |
class MapLMDataset(datasets.GeneratorBasedBuilder):
|
|
|
|
| 34 |
BUILDER_CONFIG_CLASS = MapLMBuilderConfig
|
| 35 |
BUILDER_CONFIGS = [
|
| 36 |
MapLMBuilderConfig(
|
|
|
|
| 47 |
"images": datasets.Sequence(datasets.Value("string")),
|
| 48 |
"question": datasets.Sequence(datasets.Value("string")),
|
| 49 |
"options": datasets.Sequence(datasets.Sequence(datasets.Value("string"))),
|
| 50 |
+
"answer": datasets.Sequence(datasets.Sequence(datasets.Value("string"))),
|
| 51 |
"tag": datasets.Sequence(datasets.Value("string")),
|
| 52 |
}
|
| 53 |
|
|
|
|
| 65 |
splits = []
|
| 66 |
data_root = dl_manager.download("data/")
|
| 67 |
for split in self.config.splits:
|
| 68 |
+
annotation_file = os.path.join(data_root, f"{split}_v2.json")
|
| 69 |
annotations = json.load(open(annotation_file))
|
| 70 |
if split == "test":
|
| 71 |
generator = datasets.SplitGenerator(
|
|
|
|
| 91 |
def _generate_examples(self, annotations):
|
| 92 |
for i, anno_key in enumerate(annotations):
|
| 93 |
data_item = {}
|
| 94 |
+
data_item["frame_id"] = annotations[anno_key]["id"]
|
| 95 |
+
data_item["images"] = list(annotations[anno_key]["image_paths"].values())
|
| 96 |
data_item["question"] = []
|
| 97 |
data_item["options"] = []
|
| 98 |
data_item["answer"] = []
|
| 99 |
data_item["tag"] = []
|
| 100 |
for perception_key in annotations[anno_key]["QA"]["perception"]:
|
| 101 |
+
data_item["question"].append(
|
| 102 |
+
annotations[anno_key]["QA"]["perception"][perception_key][
|
| 103 |
+
"question"
|
| 104 |
+
]
|
| 105 |
+
)
|
| 106 |
+
data_item["options"].append(
|
| 107 |
+
annotations[anno_key]["QA"]["perception"][perception_key]["option"]
|
| 108 |
+
)
|
| 109 |
+
anno_answer = annotations[anno_key]["QA"]["perception"][perception_key][
|
| 110 |
+
"answer"
|
| 111 |
+
]
|
| 112 |
+
if isinstance(anno_answer, list):
|
| 113 |
+
data_item["answer"].append(anno_answer)
|
| 114 |
+
else:
|
| 115 |
+
data_item["answer"].append([anno_answer])
|
| 116 |
+
|
| 117 |
+
data_item["tag"].append(
|
| 118 |
+
annotations[anno_key]["QA"]["perception"][perception_key]["tag"]
|
| 119 |
+
)
|
| 120 |
|
| 121 |
+
for behavior_key in annotations[anno_key]["QA"]["behavior"]:
|
| 122 |
+
data_item["question"].append(
|
| 123 |
+
annotations[anno_key]["QA"]["behavior"][behavior_key]["question"]
|
| 124 |
+
)
|
| 125 |
+
data_item["options"].append(
|
| 126 |
+
annotations[anno_key]["QA"]["behavior"][behavior_key]["option"]
|
| 127 |
+
)
|
| 128 |
+
data_item["answer"].append(
|
| 129 |
+
annotations[anno_key]["QA"]["behavior"][behavior_key]["answer"]
|
| 130 |
+
)
|
| 131 |
+
data_item["tag"].append(
|
| 132 |
+
annotations[anno_key]["QA"]["behavior"][behavior_key]["tag"]
|
| 133 |
+
)
|
| 134 |
|
| 135 |
+
yield i, data_item
|