Datasets:
File size: 2,005 Bytes
433b8a6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
import json
import csv
import os
import argparse
from pathlib import Path
def process_question(question, A, B, C):
options = [A, B, C]
question_no_options = question.replace(A, "").replace(B, "").replace(C, "")
question_no_options = question_no_options.strip().replace(",", "").strip()
while len(options) < 3:
options.append("")
return question_no_options, options
def main(json_path):
json_path = Path(json_path).resolve()
base_path = json_path.parent # All-Angles-Bench/
output_dir = base_path / "bench_tsv"
output_dir.mkdir(parents=True, exist_ok=True)
output_path = output_dir / "all_angles_bench_huggingface.tsv"
with open(json_path, 'r', encoding='utf-8') as f:
data = json.load(f)
tsv_data = []
for entry in data:
folder = entry["folder"]
category = entry["category"]
image_paths = entry["image_path"]
modified_input_images = [str(base_path / p) for p in image_paths]
question = entry["question"]
answer = entry["answer"]
index = entry["index"]
pair_idx = entry["pair_idx"]
A = entry["A"]
B = entry["B"]
C = entry["C"]
question_no_options, options = process_question(question, A, B, C)
tsv_data.append([
index, folder, category, pair_idx, modified_input_images,
question_no_options
] + options + [answer])
with open(output_path, 'w', newline='', encoding='utf-8') as tsv_file:
tsv_writer = csv.writer(tsv_file, delimiter='\t')
tsv_writer.writerow(['index', 'folder', 'category', 'pair_idx', 'image_path', 'question', 'A', 'B', 'C', 'answer'])
tsv_writer.writerows(tsv_data)
print(f"Saved TSV to {output_path}")
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('--input', required=True, help='Path to the data.json file (e.g., All-Angles-Bench/data.json)')
args = parser.parse_args()
main(args.input)
|