File size: 2,439 Bytes
0dd0bac
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python3
"""
Create a samples directory with a few examples from each curve type.
"""
import os
import shutil
import json

# Configuration
SAMPLES_PER_TYPE = 3  # Number of samples per curve type per dataset
SOURCE_DIR = "results"
TARGET_DIR = "samples"

def create_samples():
    # Remove existing samples directory
    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)
        
        # Copy summary.json
        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)
            
            # Get PNG files and sort them
            png_files = sorted([f for f in os.listdir(src_type_dir) if f.endswith('.png')])
            
            # Select samples (first, middle, last)
            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]]
            
            # Copy selected files
            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()