| |
| """ |
| Create a samples directory with a few examples from each curve type. |
| """ |
| import os |
| import shutil |
| import json |
|
|
| |
| SAMPLES_PER_TYPE = 3 |
| SOURCE_DIR = "results" |
| TARGET_DIR = "samples" |
|
|
| def create_samples(): |
| |
| if os.path.exists(TARGET_DIR): |
| shutil.rmtree(TARGET_DIR) |
| |
| os.makedirs(TARGET_DIR) |
| |
| datasets = ['dev', 'test', 'train'] |
| curve_types = ['circle', 'ellipse', 'hyperbola', 'parabola'] |
| |
| total_copied = 0 |
| |
| for dataset in datasets: |
| dataset_dir = os.path.join(SOURCE_DIR, dataset) |
| if not os.path.exists(dataset_dir): |
| continue |
| |
| target_dataset_dir = os.path.join(TARGET_DIR, dataset) |
| os.makedirs(target_dataset_dir, exist_ok=True) |
| |
| |
| summary_src = os.path.join(dataset_dir, 'summary.json') |
| if os.path.exists(summary_src): |
| shutil.copy(summary_src, target_dataset_dir) |
| |
| for curve_type in curve_types: |
| src_type_dir = os.path.join(dataset_dir, curve_type) |
| if not os.path.exists(src_type_dir): |
| continue |
| |
| target_type_dir = os.path.join(target_dataset_dir, curve_type) |
| os.makedirs(target_type_dir, exist_ok=True) |
| |
| |
| png_files = sorted([f for f in os.listdir(src_type_dir) if f.endswith('.png')]) |
| |
| |
| if len(png_files) == 0: |
| continue |
| elif len(png_files) <= SAMPLES_PER_TYPE: |
| selected = png_files |
| else: |
| indices = [0, len(png_files)//2, len(png_files)-1] |
| selected = [png_files[i] for i in indices[:SAMPLES_PER_TYPE]] |
| |
| |
| for filename in selected: |
| src = os.path.join(src_type_dir, filename) |
| dst = os.path.join(target_type_dir, filename) |
| shutil.copy(src, dst) |
| total_copied += 1 |
| print(f" Copied: {dataset}/{curve_type}/{filename}") |
| |
| print(f"\n✓ Created samples directory with {total_copied} files") |
| print(f" Location: {os.path.abspath(TARGET_DIR)}") |
|
|
| if __name__ == "__main__": |
| create_samples() |
|
|