KHUjongseo commited on
Commit
e25f555
·
verified ·
1 Parent(s): 97c1a63

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. close_ended.json +0 -0
  2. making_json.py +107 -0
close_ended.json CHANGED
The diff for this file is too large to render. See raw diff
 
making_json.py ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ 로컬 이미지 디렉토리에서 lmms-eval용 JSON 데이터셋 2종 생성
3
+ - close_ended.json : 4지선다 (A/B/C/D)
4
+ - open_ended.json : 자유 응답 (Up/Down/Left/Right)
5
+ """
6
+
7
+ import os
8
+ import json
9
+ import glob
10
+
11
+ # ============================================================
12
+ # 설정
13
+ # ============================================================
14
+ DATA_ROOT = "/data/dataset/vlm_direction/object_location_4_class_subset_1of5/val"
15
+ OUTPUT_DIR = "./"
16
+
17
+ # 폴더명 → 영어 레이블 매핑
18
+ LABEL_MAP = {
19
+ "up": "Up",
20
+ "down": "Down",
21
+ "left": "Left",
22
+ "right": "Right",
23
+ }
24
+
25
+ # Close-ended 선택지 (고정 순서)
26
+ OPTIONS = ["Up", "Down", "Left", "Right"]
27
+ OPTION_LETTERS = ["A", "B", "C", "D"]
28
+
29
+ # ============================================================
30
+ # 데이터 수집
31
+ # ============================================================
32
+ close_ended_data = []
33
+ open_ended_data = []
34
+
35
+ idx = 0
36
+ for folder_name, eng_label in LABEL_MAP.items():
37
+ folder_path = os.path.join(DATA_ROOT, folder_name)
38
+ if not os.path.isdir(folder_path):
39
+ print(f"[WARNING] 폴더 없음: {folder_path}")
40
+ continue
41
+
42
+ image_files = sorted(
43
+ glob.glob(os.path.join(folder_path, "*.png"))
44
+ + glob.glob(os.path.join(folder_path, "*.jpg"))
45
+ + glob.glob(os.path.join(folder_path, "*.jpeg"))
46
+ )
47
+ print(f"[INFO] {folder_name}: {len(image_files)} images found")
48
+
49
+ for img_path in image_files:
50
+ # abs_path = os.path.abspath(img_path)
51
+ filename = os.path.basename(img_path)
52
+
53
+ # 정답 옵션 letter (A/B/C/D)
54
+ answer_idx = OPTIONS.index(eng_label)
55
+ answer_letter = OPTION_LETTERS[answer_idx]
56
+
57
+ # --------------------------------------------------
58
+ # 1) Close-ended (4지선다)
59
+ # --------------------------------------------------
60
+ close_ended_data.append({
61
+ "id": idx,
62
+ "image": filename,
63
+ "question": "From the viewer's perspective, where is the object located in the image?",
64
+ "options": OPTIONS, # ["Up", "Down", "Left", "Right"]
65
+ "answer": answer_letter, # "A" / "B" / "C" / "D"
66
+ "answer_text": eng_label, # "Up" / "Down" / "Left" / "Right"
67
+ "category": folder_name,
68
+ })
69
+
70
+ # --------------------------------------------------
71
+ # 2) Open-ended (자유 응답)
72
+ # --------------------------------------------------
73
+ open_ended_data.append({
74
+ "id": idx,
75
+ "image": filename,
76
+ "question": "From the viewer's perspective, where is the object located in the image? Answer with one of: Up, Down, Left, Right.",
77
+ "answer": eng_label, # "Up" / "Down" / "Left" / "Right"
78
+ "category": folder_name,
79
+ })
80
+
81
+ idx += 1
82
+
83
+ # ============================================================
84
+ # JSON 저장
85
+ # ============================================================
86
+ os.makedirs(OUTPUT_DIR, exist_ok=True)
87
+
88
+ close_path = os.path.join(OUTPUT_DIR, "close_ended.json")
89
+ open_path = os.path.join(OUTPUT_DIR, "open_ended.json")
90
+
91
+ with open(close_path, "w", encoding="utf-8") as f:
92
+ json.dump(close_ended_data, f, ensure_ascii=False, indent=2)
93
+
94
+ with open(open_path, "w", encoding="utf-8") as f:
95
+ json.dump(open_ended_data, f, ensure_ascii=False, indent=2)
96
+
97
+ print(f"\n{'='*60}")
98
+ print(f"Total {idx} samples processed")
99
+ print(f"Close-ended → {close_path} ({len(close_ended_data)} samples)")
100
+ print(f"Open-ended → {open_path} ({len(open_ended_data)} samples)")
101
+ print(f"{'='*60}")
102
+
103
+ # 샘플 출력
104
+ print("\n[Sample] Close-ended:")
105
+ print(json.dumps(close_ended_data[0], ensure_ascii=False, indent=2))
106
+ print("\n[Sample] Open-ended:")
107
+ print(json.dumps(open_ended_data[0], ensure_ascii=False, indent=2))