Datasets:
Update L1 questions and dataset structure
Browse files- Spatial457.py +64 -0
- questions/L1_single.json +0 -0
Spatial457.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import json
|
| 3 |
+
import datasets
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class Spatial457(datasets.GeneratorBasedBuilder):
|
| 7 |
+
BUILDER_CONFIGS = [
|
| 8 |
+
datasets.BuilderConfig(name="L1_single"),
|
| 9 |
+
datasets.BuilderConfig(name="L2_objects"),
|
| 10 |
+
datasets.BuilderConfig(name="L3_2d_spatial"),
|
| 11 |
+
datasets.BuilderConfig(name="L4_occ"),
|
| 12 |
+
datasets.BuilderConfig(name="L4_pose"),
|
| 13 |
+
datasets.BuilderConfig(name="L5_6d_spatial"),
|
| 14 |
+
datasets.BuilderConfig(name="L5_collision"),
|
| 15 |
+
]
|
| 16 |
+
|
| 17 |
+
def _info(self):
|
| 18 |
+
return datasets.DatasetInfo(
|
| 19 |
+
description="Spatial457: A multi-task spatial visual question answering dataset.",
|
| 20 |
+
features=datasets.Features({
|
| 21 |
+
"image": datasets.Image(), # 自动加载图片
|
| 22 |
+
"image_filename": datasets.Value("string"),
|
| 23 |
+
"question": datasets.Value("string"),
|
| 24 |
+
"answer": datasets.Value("string"), # 会自动处理 True / False / str
|
| 25 |
+
"question_index": datasets.Value("int32"),
|
| 26 |
+
"program": datasets.Sequence(
|
| 27 |
+
{
|
| 28 |
+
"type": datasets.Value("string"),
|
| 29 |
+
"inputs": datasets.Sequence(datasets.Value("int32")),
|
| 30 |
+
"_output": datasets.Value("string"),
|
| 31 |
+
"value_inputs": datasets.Sequence(datasets.Value("string")),
|
| 32 |
+
}
|
| 33 |
+
),
|
| 34 |
+
}),
|
| 35 |
+
supervised_keys=None,
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
def _split_generators(self, dl_manager):
|
| 39 |
+
data_dir = dl_manager.manual_dir # expects local `images/` and `questions/`
|
| 40 |
+
|
| 41 |
+
task_json = os.path.join(data_dir, "questions", f"{self.config.name}.json")
|
| 42 |
+
image_dir = os.path.join(data_dir, "images")
|
| 43 |
+
|
| 44 |
+
return [
|
| 45 |
+
datasets.SplitGenerator(
|
| 46 |
+
name=datasets.Split.TRAIN,
|
| 47 |
+
gen_kwargs={"json_file": task_json, "image_dir": image_dir}
|
| 48 |
+
)
|
| 49 |
+
]
|
| 50 |
+
|
| 51 |
+
def _generate_examples(self, json_file, image_dir):
|
| 52 |
+
with open(json_file, "r", encoding="utf-8") as f:
|
| 53 |
+
all_data = json.load(f)["questions"]
|
| 54 |
+
|
| 55 |
+
for idx, q in enumerate(all_data):
|
| 56 |
+
img_path = os.path.join(image_dir, q["image_filename"])
|
| 57 |
+
yield idx, {
|
| 58 |
+
"image": img_path,
|
| 59 |
+
"image_filename": q["image_filename"],
|
| 60 |
+
"question": q["question"],
|
| 61 |
+
"answer": str(q["answer"]),
|
| 62 |
+
"question_index": q["question_index"],
|
| 63 |
+
"program": q["program"],
|
| 64 |
+
}
|
questions/L1_single.json
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|