| | """ |
| | 로컬 이미지 디렉토리에서 lmms-eval용 JSON 데이터셋 2종 생성 |
| | - close_ended.json : 4지선다 (A/B/C/D) |
| | - open_ended.json : 자유 응답 (Up/Down/Left/Right) |
| | """ |
| |
|
| | import os |
| | import json |
| | import glob |
| |
|
| | |
| | |
| | |
| | DATA_ROOT = "/data/dataset/vlm_direction/object_location_4_class_subset_1of5/val" |
| | OUTPUT_DIR = "./" |
| |
|
| | |
| | LABEL_MAP = { |
| | "up": "Up", |
| | "down": "Down", |
| | "left": "Left", |
| | "right": "Right", |
| | } |
| |
|
| | |
| | OPTIONS = ["Up", "Down", "Left", "Right"] |
| | OPTION_LETTERS = ["A", "B", "C", "D"] |
| |
|
| | |
| | |
| | |
| | close_ended_data = [] |
| | open_ended_data = [] |
| |
|
| | idx = 0 |
| | for folder_name, eng_label in LABEL_MAP.items(): |
| | folder_path = os.path.join(DATA_ROOT, folder_name) |
| | if not os.path.isdir(folder_path): |
| | print(f"[WARNING] 폴더 없음: {folder_path}") |
| | continue |
| |
|
| | image_files = sorted( |
| | glob.glob(os.path.join(folder_path, "*.png")) |
| | + glob.glob(os.path.join(folder_path, "*.jpg")) |
| | + glob.glob(os.path.join(folder_path, "*.jpeg")) |
| | ) |
| | print(f"[INFO] {folder_name}: {len(image_files)} images found") |
| |
|
| | for img_path in image_files: |
| | |
| | filename = os.path.basename(img_path) |
| |
|
| | |
| | answer_idx = OPTIONS.index(eng_label) |
| | answer_letter = OPTION_LETTERS[answer_idx] |
| |
|
| | |
| | |
| | |
| | close_ended_data.append({ |
| | "id": idx, |
| | "image": filename, |
| | "question": "From the viewer's perspective, where is the object located in the image?", |
| | "options": OPTIONS, |
| | "answer": answer_letter, |
| | "answer_text": eng_label, |
| | "category": folder_name, |
| | }) |
| |
|
| | |
| | |
| | |
| | open_ended_data.append({ |
| | "id": idx, |
| | "image": filename, |
| | "question": "From the viewer's perspective, where is the object located in the image? Answer with one of: Up, Down, Left, Right.", |
| | "answer": eng_label, |
| | "category": folder_name, |
| | }) |
| |
|
| | idx += 1 |
| |
|
| | |
| | |
| | |
| | os.makedirs(OUTPUT_DIR, exist_ok=True) |
| |
|
| | close_path = os.path.join(OUTPUT_DIR, "close_ended.json") |
| | open_path = os.path.join(OUTPUT_DIR, "open_ended.json") |
| |
|
| | with open(close_path, "w", encoding="utf-8") as f: |
| | json.dump(close_ended_data, f, ensure_ascii=False, indent=2) |
| |
|
| | with open(open_path, "w", encoding="utf-8") as f: |
| | json.dump(open_ended_data, f, ensure_ascii=False, indent=2) |
| |
|
| | print(f"\n{'='*60}") |
| | print(f"Total {idx} samples processed") |
| | print(f"Close-ended → {close_path} ({len(close_ended_data)} samples)") |
| | print(f"Open-ended → {open_path} ({len(open_ended_data)} samples)") |
| | print(f"{'='*60}") |
| |
|
| | |
| | print("\n[Sample] Close-ended:") |
| | print(json.dumps(close_ended_data[0], ensure_ascii=False, indent=2)) |
| | print("\n[Sample] Open-ended:") |
| | print(json.dumps(open_ended_data[0], ensure_ascii=False, indent=2)) |