SCMayS commited on
Commit
3fd5d0e
·
verified ·
1 Parent(s): ed95db1

Upload create_metadata_sft_icl.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. create_metadata_sft_icl.py +512 -0
create_metadata_sft_icl.py ADDED
@@ -0,0 +1,512 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import re
3
+ import glob
4
+ import json
5
+ import argparse
6
+ import random
7
+ import uuid
8
+ from tqdm import tqdm
9
+ from pathlib import Path
10
+ from collections import defaultdict
11
+
12
+ def parse_ground_truth(name):
13
+ """Extract ground truth rotation axis and angle from filename or folder name"""
14
+ # Remove file extension if present
15
+ basename = name.split(".")[0] if "." in name else name
16
+
17
+ parts = basename.split("_")
18
+ if len(parts) >= 4: # figXXXX_XXX_axis_angle
19
+ rotation_axis = parts[-2] # Second to last element is axis
20
+ rotation_angle = int(parts[-1]) # Last element is angle
21
+
22
+ # Convert negative angles to 0-360 range
23
+ if rotation_angle < 0:
24
+ rotation_angle += 360
25
+
26
+ return rotation_axis, rotation_angle
27
+
28
+ print(f"Warning: Could not parse name: {basename}")
29
+ return None, None
30
+
31
+ def load_examples(example_dir, generation_mode):
32
+ """Load example images from the example directory"""
33
+ if generation_mode == "combined":
34
+ # Load all single PNG files from the example directory
35
+ files = glob.glob(os.path.join(example_dir, "*.png"))
36
+ print(f"Found {len(files)} combined example images in {example_dir}")
37
+ return files
38
+ else: # separate mode
39
+ # Find all folders in the example directory
40
+ folders = [f for f in glob.glob(os.path.join(example_dir, "*")) if os.path.isdir(f)]
41
+ # Filter folders that contain both _ini.png and _rot.png files
42
+ valid_folders = []
43
+ for folder in folders:
44
+ folder_name = os.path.basename(folder)
45
+ ini_file = os.path.join(folder, f"{folder_name}_ini.png")
46
+ rot_file = os.path.join(folder, f"{folder_name}_rot.png")
47
+ if os.path.exists(ini_file) and os.path.exists(rot_file):
48
+ valid_folders.append(folder)
49
+
50
+ print(f"Found {len(valid_folders)} example folder pairs in {example_dir}")
51
+ return valid_folders
52
+
53
+ def organize_examples(examples, generation_mode):
54
+ """Organize examples by rotation axis and angle"""
55
+ organized = defaultdict(list)
56
+ for example in examples:
57
+ basename = os.path.basename(example)
58
+ if generation_mode == "combined":
59
+ basename = basename.split(".")[0]
60
+
61
+ axis, angle = parse_ground_truth(basename)
62
+ if axis is None or angle is None:
63
+ continue
64
+
65
+ key = (axis, angle)
66
+ organized[key].append(example)
67
+
68
+ # Print statistics
69
+ print("\nDistribution of examples by axis-angle:")
70
+ for key, examples_list in organized.items():
71
+ print(f" {key[0]}-axis, {key[1]} degrees: {len(examples_list)} examples")
72
+
73
+ return dict(organized)
74
+
75
+ def select_example(organized_examples, test_axis):
76
+ """Select a single random example for the test case"""
77
+ # Collect all examples for this axis regardless of angle
78
+ all_examples_for_axis = []
79
+ for (axis, angle), example_list in organized_examples.items():
80
+ if axis == test_axis:
81
+ for example in example_list:
82
+ all_examples_for_axis.append((example, angle))
83
+
84
+ # If we have any examples for this axis, select one randomly
85
+ if all_examples_for_axis and len(all_examples_for_axis) > 0:
86
+ return random.choice(all_examples_for_axis)
87
+ else:
88
+ print(f"Warning: No examples found for rotation around {test_axis}-axis")
89
+ return None
90
+
91
+ def construct_prompt_with_example(axis, angle_increment, example=None, difficulty="easy", generation_mode="combined"):
92
+ """Create prompt for the VLM with an in-context example"""
93
+ # Generate list of all possible rotation angles based on angle increment
94
+ possible_angles = []
95
+ current_angle = 0 + angle_increment
96
+ while current_angle < 360:
97
+ possible_angles.append(current_angle)
98
+ current_angle += angle_increment
99
+
100
+ # Common instructions for both modes
101
+ coordinate_system = (
102
+ f"The 3D Cartesian coordinate system is defined as follows: "
103
+ f"\n- x-axis: points horizontally from left to right (positive direction is right)"
104
+ f"\n- y-axis: points vertically from bottom to top (positive direction is up)"
105
+ f"\n- z-axis: points from inside the image toward the viewer (positive direction is out of the screen)"
106
+ f"\n\nWhen discussing rotations around an axis, imagine looking along the positive direction of that axis (as if looking from the origin toward the positive end)."
107
+ )
108
+
109
+ angle_constraints = (
110
+ f"The rotation angle is always a multiple of {angle_increment} degrees between 0 and 360 degrees inclusive. "
111
+ f"A positive angle means rotation in the CLOCKWISE direction when looking along the positive direction of the axis. "
112
+ )
113
+
114
+ # Add example text if an example is provided
115
+ example_text = ""
116
+ if example:
117
+ _, example_angle = example
118
+ if generation_mode == "combined":
119
+ example_text = f"\n### EXAMPLE OF ROTATION ###\n\nExample: Image 1 shows a 3D object with its left half showing the initial view and right half showing a {example_angle} degree rotation around the {axis}-axis.\n"
120
+ else: # separate mode
121
+ example_text = f"\n### EXAMPLE OF ROTATION ###\n\nExample: Image 1 shows the initial view and Image 2 shows the object after a {example_angle} degree rotation around the {axis}-axis.\n"
122
+
123
+ # Different instructions based on difficulty
124
+ if difficulty == "easy":
125
+ # For easy mode - axis is provided, internal reasoning but only output number
126
+ thinking_instructions = (
127
+ f"IMPORTANT: Please follow this systematic approach to determine the rotation angle:"
128
+ f"\n\n1. First, analyze the object's features in both views to understand its structure."
129
+ f"\n\n2. For the {axis}-axis rotation, you must evaluate ALL of these possible rotation angles: {possible_angles}"
130
+ f"\n - For each angle in the list, mentally visualize what the object would look like after rotating around the {axis}-axis by that amount"
131
+ f"\n - Compare these visualizations with the actual second view"
132
+ f"\n - DO NOT make a decision until you have evaluated all possible angles in the list"
133
+ f"\n\n3. After evaluating all angles, choose the one that best matches the observed changes"
134
+ f"\n\n4. Verify your answer by mentally applying the rotation to confirm it matches the second view"
135
+ )
136
+
137
+ # Updated response format to match rot_pred_sft.py
138
+ response_format = (
139
+ f"IMPORTANT: You must ONLY output the rotation angle as a number from this list: {possible_angles}. "
140
+ f"Your output should contain ONLY the number. "
141
+ f"Do NOT include any reasoning, explanation, or additional text - ONLY the number."
142
+ f"\n\nExample of correct output format: 30"
143
+ f"\n\nIncorrect output formats:"
144
+ f"\n\"I think it's 30 degrees\""
145
+ f"\n\"The rotation angle is 30\""
146
+ f"\n\"30 degrees\""
147
+ )
148
+
149
+ task_description = (
150
+ f"Your task is to determine the angle of rotation around the {axis}-axis in degrees."
151
+ )
152
+
153
+ else: # hard mode - axis is not provided
154
+ thinking_instructions = (
155
+ f"IMPORTANT: Please follow this systematic approach to determine the rotation:"
156
+ f"\n\n1. First, analyze the object's features in both views to understand its structure."
157
+ f"\n\n2. Consider what would happen if rotation occurred around each of the three axes (x, y, and z):"
158
+ f"\n - For x-axis rotation: What specific features would change and how?"
159
+ f"\n - For y-axis rotation: What specific features would change and how?"
160
+ f"\n - For z-axis rotation: What specific features would change and how?"
161
+ f"\n - Based on the observed changes, explain which axis makes the most sense and why."
162
+ f"\n\n3. Once you've determined the most likely axis, evaluate ALL of these possible rotation angles: {possible_angles}"
163
+ f"\n - For each angle in the list, describe what the object would look like after rotating around your chosen axis by that amount"
164
+ f"\n - Compare these descriptions with the actual second view"
165
+ f"\n - DO NOT make a decision until you have evaluated all angles in the list"
166
+ f"\n\n4. After evaluating all angles, choose the one that best matches the observed changes"
167
+ )
168
+
169
+ response_format = (
170
+ f"Place your detailed reasoning process in <thinking></thinking> tags. Your reasoning should include:"
171
+ f"\n- Analysis of how rotation around each axis would affect the object"
172
+ f"\n- Systematic evaluation of possible rotation angles from the provided list"
173
+ f"\n- Specific visual features you used to determine your answer"
174
+ f"\n\nThen provide your final answer in <rotation_axis></rotation_axis> and <rotation_angle></rotation_angle> tags respectively (use only x, y, or z for axis and only a number from the list for angle)."
175
+ f"\ni.e., <thinking> your reasoning process here </thinking><rotation_axis> your predicted axis here </rotation_axis><rotation_angle> your predicted degrees here </rotation_angle>"
176
+ )
177
+
178
+ task_description = (
179
+ f"Your task is to determine which axis the object was rotated around and by what angle."
180
+ )
181
+
182
+ # Generate the prompt based on generation mode
183
+ if generation_mode == "combined":
184
+ test_img_num = 2 if example else 1 # If we have an example, test image is #2
185
+ prompt = (
186
+ f"IMPORTANT: I'm showing you {2 if example else 1} image{'s' if example else ''} of 3D objects. "
187
+ f"{'Each' if example else 'The'} image contains TWO separate 3D renderings side-by-side. "
188
+ f"\n\nThe LEFT HALF shows a 3D object in its initial orientation. "
189
+ f"The RIGHT HALF shows the SAME 3D object after being rotated."
190
+ f"\n\n{task_description}"
191
+ f"\n\n{coordinate_system}"
192
+ f"\n\n{angle_constraints}"
193
+ f"\n\n{example_text}"
194
+ f"\n\n### YOUR TASK ###"
195
+ f"\nNow, for Image {test_img_num}, determine the angle of rotation around the {axis}-axis."
196
+ f"\n{'' if not example else 'Based on the example provided, '}analyze Image {test_img_num} carefully."
197
+ f"\n\n{thinking_instructions}"
198
+ f"\n\n{response_format}"
199
+ )
200
+ else: # separate mode
201
+ # Calculate image numbers based on examples
202
+ test_img_start = 3 if example else 1 # If we have an example (2 images), test starts at #3
203
+ test_img_end = 4 if example else 2
204
+ prompt = (
205
+ f"I'm showing you {4 if example else 2} images of 3D objects. "
206
+ f"{'For each example or test case, ' if example else ''}two images represent the same object before and after rotation."
207
+ f"\n\n{task_description}"
208
+ f"\n\n{coordinate_system}"
209
+ f"\n\n{angle_constraints}"
210
+ f"\n\n{example_text}"
211
+ f"\n\n### YOUR TASK ###"
212
+ f"\nNow, determine the angle of rotation around the {axis}-axis from Image {test_img_start} to Image {test_img_end}."
213
+ f"\n{'' if not example else 'Based on the example provided, '}analyze the rotation carefully."
214
+ f"\n\n{thinking_instructions}"
215
+ f"\n\n{response_format}"
216
+ )
217
+
218
+ return prompt
219
+
220
+ def create_metadata_jsonl_combined(input_dir, output_file, example_dir=None, angle_increment=30, difficulty="easy"):
221
+ """Create metadata JSONL file for all images in input_dir (combined mode)"""
222
+ # Get all PNG files in the input directory
223
+ png_files = glob.glob(os.path.join(input_dir, "*.png"))
224
+
225
+ # Sort files to ensure consistent order
226
+ png_files = sorted(png_files)
227
+
228
+ if not png_files:
229
+ print(f"No PNG files found in {input_dir}")
230
+ return
231
+
232
+ print(f"Found {len(png_files)} PNG files in {input_dir}")
233
+
234
+ # Load and organize examples if example_dir is provided
235
+ organized_examples = None
236
+ if example_dir:
237
+ examples = load_examples(example_dir, "combined")
238
+ organized_examples = organize_examples(examples, "combined")
239
+
240
+ # Create output directory if it doesn't exist
241
+ output_dir = os.path.dirname(output_file)
242
+ os.makedirs(output_dir, exist_ok=True)
243
+
244
+ # Process each file and create metadata entries
245
+ entries = []
246
+
247
+ for png_file in tqdm(png_files, desc="Creating metadata for combined mode"):
248
+ # Parse ground truth from filename
249
+ axis, angle = parse_ground_truth(os.path.basename(png_file))
250
+
251
+ if axis is None or angle is None:
252
+ print(f"Skipping {png_file} - could not parse ground truth")
253
+ continue
254
+
255
+ # Get the relative path to the image
256
+ rel_path = os.path.relpath(png_file, os.path.dirname(output_file))
257
+
258
+ # Generate a unique ID based on the filename
259
+ image_base_id = os.path.splitext(os.path.basename(png_file))[0]
260
+
261
+ # Select an example if examples are available
262
+ example = None
263
+ if organized_examples:
264
+ example = select_example(organized_examples, axis)
265
+
266
+ # Construct prompt with or without example
267
+ prompt = construct_prompt_with_example(axis, angle_increment, example, difficulty, generation_mode="combined")
268
+
269
+ # Create assistant response based on difficulty
270
+ if difficulty == "easy":
271
+ # For easy mode, just output the number
272
+ assistant_content = f"{angle}"
273
+ else:
274
+ # For hard mode, include both axis and angle in XML tags
275
+ assistant_content = f"<thinking>Detailed reasoning about rotation axis and angle...</thinking><rotation_axis>{axis}</rotation_axis><rotation_angle>{angle}</rotation_angle>"
276
+
277
+ # Create the conversations array
278
+ conversations = []
279
+
280
+ # Add human message with prompt and images
281
+ human_value = ""
282
+
283
+ # Add example image if available
284
+ if example:
285
+ example_path, _ = example
286
+ example_rel_path = os.path.relpath(example_path, os.path.dirname(output_file))
287
+ human_value += f"<image>{example_rel_path}</image>\n"
288
+
289
+ # Add test image
290
+ human_value += f"<image>{rel_path}</image>\n{prompt}"
291
+
292
+ conversations.append({
293
+ "from": "human",
294
+ "value": human_value
295
+ })
296
+
297
+ # Add assistant response
298
+ conversations.append({
299
+ "from": "gpt",
300
+ "value": assistant_content
301
+ })
302
+
303
+ # Create entry with the correct format
304
+ entry = {
305
+ "id": image_base_id,
306
+ "image": rel_path,
307
+ "conversations": conversations
308
+ }
309
+
310
+ entries.append(entry)
311
+
312
+ # Write entries to JSONL file
313
+ with open(output_file, 'w') as f:
314
+ for entry in entries:
315
+ f.write(json.dumps(entry) + '\n')
316
+
317
+ print(f"\nSummary for combined mode:")
318
+ print(f" Found {len(png_files)} PNG files")
319
+ print(f" Created metadata for {len(entries)} entries")
320
+ print(f" Output file: {output_file}")
321
+
322
+ def create_metadata_jsonl_separate(input_dir, output_file, example_dir=None, angle_increment=30, difficulty="easy"):
323
+ """Create metadata JSONL file for folders in input_dir (separate mode)"""
324
+ # Get all directories in the input directory
325
+ folders = [f for f in glob.glob(os.path.join(input_dir, "*"))
326
+ if os.path.isdir(f) and os.path.basename(f) != "examples"]
327
+
328
+ # Sort folders to ensure consistent order
329
+ folders = sorted(folders)
330
+
331
+ if not folders:
332
+ print(f"No folders found in {input_dir}")
333
+ return
334
+
335
+ print(f"Found {len(folders)} folders in {input_dir}")
336
+
337
+ # Load and organize examples if example_dir is provided
338
+ organized_examples = None
339
+ if example_dir:
340
+ examples = load_examples(example_dir, "separate")
341
+ organized_examples = organize_examples(examples, "separate")
342
+
343
+ # Create output directory if it doesn't exist
344
+ output_dir = os.path.dirname(output_file)
345
+ os.makedirs(output_dir, exist_ok=True)
346
+
347
+ # Process each folder and create metadata entries
348
+ entries = []
349
+ valid_folders = 0
350
+
351
+ for folder in tqdm(folders, desc="Creating metadata for separate mode"):
352
+ folder_name = os.path.basename(folder)
353
+
354
+ # Parse ground truth from folder name
355
+ axis, angle = parse_ground_truth(folder_name)
356
+
357
+ if axis is None or angle is None:
358
+ print(f"Skipping {folder} - could not parse ground truth")
359
+ continue
360
+
361
+ # Check for the two required images in the folder
362
+ ini_path = os.path.join(folder, f"{folder_name}_ini.png")
363
+ rot_path = os.path.join(folder, f"{folder_name}_rot.png")
364
+
365
+ if not os.path.exists(ini_path):
366
+ print(f"Skipping {folder} - missing initial view image")
367
+ continue
368
+
369
+ if not os.path.exists(rot_path):
370
+ print(f"Skipping {folder} - missing rotated view image")
371
+ continue
372
+
373
+ # Get the relative paths to the images
374
+ rel_ini_path = os.path.relpath(ini_path, os.path.dirname(output_file))
375
+ rel_rot_path = os.path.relpath(rot_path, os.path.dirname(output_file))
376
+
377
+ # Select an example if examples are available
378
+ example = None
379
+ image_paths = []
380
+
381
+ if organized_examples:
382
+ example = select_example(organized_examples, axis)
383
+
384
+ # Construct prompt with or without example
385
+ prompt = construct_prompt_with_example(axis, angle_increment, example, difficulty, generation_mode="separate")
386
+
387
+ # Create assistant response based on difficulty
388
+ if difficulty == "easy":
389
+ # For easy mode, just output the number
390
+ assistant_content = f"{angle}"
391
+ else:
392
+ # For hard mode, include both axis and angle in XML tags
393
+ assistant_content = f"<thinking>Detailed reasoning about rotation axis and angle...</thinking><rotation_axis>{axis}</rotation_axis><rotation_angle>{angle}</rotation_angle>"
394
+
395
+ # Create the conversations array
396
+ conversations = []
397
+
398
+ # Prepare images array for the entry
399
+ all_image_paths = []
400
+
401
+ # Add example images if available
402
+ if example:
403
+ example_folder, _ = example
404
+ example_folder_name = os.path.basename(example_folder)
405
+ example_ini_path = os.path.join(example_folder, f"{example_folder_name}_ini.png")
406
+ example_rot_path = os.path.join(example_folder, f"{example_folder_name}_rot.png")
407
+
408
+ example_rel_ini_path = os.path.relpath(example_ini_path, os.path.dirname(output_file))
409
+ example_rel_rot_path = os.path.relpath(example_rot_path, os.path.dirname(output_file))
410
+
411
+ all_image_paths.append(example_rel_ini_path)
412
+ all_image_paths.append(example_rel_rot_path)
413
+
414
+ # Add test images
415
+ all_image_paths.append(rel_ini_path)
416
+ all_image_paths.append(rel_rot_path)
417
+
418
+ # Add human message with prompt and images - format with <image> tags at the beginning
419
+ human_value = "<image>\n<image>\n<image>\n<image>\n" + prompt
420
+
421
+ conversations.append({
422
+ "from": "human",
423
+ "value": human_value
424
+ })
425
+
426
+ # Add assistant response
427
+ conversations.append({
428
+ "from": "gpt",
429
+ "value": assistant_content
430
+ })
431
+
432
+ # Create entry with the correct format
433
+ entry = {
434
+ "id": folder_name,
435
+ "image": all_image_paths,
436
+ "conversations": conversations
437
+ }
438
+
439
+ entries.append(entry)
440
+ valid_folders += 1
441
+
442
+ # Write entries to JSONL file
443
+ with open(output_file, 'w') as f:
444
+ for entry in entries:
445
+ f.write(json.dumps(entry) + '\n')
446
+
447
+ print(f"\nSummary for separate mode:")
448
+ print(f" Found {len(folders)} folders")
449
+ print(f" Created metadata for {valid_folders} valid folders")
450
+ print(f" Output file: {output_file}")
451
+
452
+ def main():
453
+ parser = argparse.ArgumentParser(description="Create metadata JSONL for rotation dataset")
454
+ parser.add_argument('--input-dir', type=str, required=True,
455
+ help="Directory containing rotation dataset images or folders")
456
+ parser.add_argument('--output-file', type=str, default="metadata.jsonl",
457
+ help="Output JSONL file path")
458
+ parser.add_argument('--example-dir', type=str, default=None,
459
+ help="Directory containing example images for in-context learning")
460
+ parser.add_argument('--angle-increment', type=int, default=30,
461
+ help="Angle increment used in the dataset (e.g., 30, 45, 90)")
462
+ parser.add_argument('--difficulty', type=str, choices=["easy", "hard"], default="easy",
463
+ help="Difficulty mode: easy (axis provided) or hard (axis not provided)")
464
+ parser.add_argument('--generation-mode', type=str, choices=["combined", "separate"], default="combined",
465
+ help="Mode for dataset generation (combined = one image with both views, separate = folder with two images)")
466
+ parser.add_argument('--random-seed', type=int, default=None,
467
+ help="Random seed for example selection (None for true randomness)")
468
+
469
+ args = parser.parse_args()
470
+
471
+ # Set random seed for reproducibility if provided
472
+ if args.random_seed is not None:
473
+ print(f"Using fixed random seed: {args.random_seed}")
474
+ random.seed(args.random_seed)
475
+ else:
476
+ print("Using true randomness (different examples each run)")
477
+
478
+ print(f"Creating metadata JSONL for rotation dataset:")
479
+ print(f"Input directory: {args.input_dir}")
480
+ print(f"Output file: {args.output_file}")
481
+
482
+ if args.example_dir:
483
+ print(f"Example directory: {args.example_dir}")
484
+
485
+ print(f"Angle increment: {args.angle_increment} degrees")
486
+ print(f"Difficulty mode: {args.difficulty}")
487
+ print(f"Generation mode: {args.generation_mode}")
488
+
489
+ # Check if example_dir is None but there's an 'examples' subdirectory in input_dir
490
+ if args.example_dir is None and os.path.exists(os.path.join(args.input_dir, "examples")):
491
+ args.example_dir = os.path.join(args.input_dir, "examples")
492
+ print(f"Using examples directory: {args.example_dir}")
493
+
494
+ if args.generation_mode == "combined":
495
+ create_metadata_jsonl_combined(
496
+ input_dir=args.input_dir,
497
+ output_file=args.output_file,
498
+ example_dir=args.example_dir,
499
+ angle_increment=args.angle_increment,
500
+ difficulty=args.difficulty
501
+ )
502
+ else: # separate mode
503
+ create_metadata_jsonl_separate(
504
+ input_dir=args.input_dir,
505
+ output_file=args.output_file,
506
+ example_dir=args.example_dir,
507
+ angle_increment=args.angle_increment,
508
+ difficulty=args.difficulty
509
+ )
510
+
511
+ if __name__ == "__main__":
512
+ main()