File size: 3,959 Bytes
9a85a36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env python3
"""
Example script for evaluating FID and IS scores of generated images.
"""
import torch

from eval import (
    clear_evaluation_cache,
    run_evaluation_only, 
    create_image_paths_file
)
from metric import ( 
    print_memory_usage, 
    force_memory_cleanup, 
)


def main():
    # Configuration
    real_cache_dir = "/lustre/scratch/client/movian/research/users/phuclh12/Code/minHiWave/output_invsr/eval_cache"
    output_dir = "/lustre/scratch/client/movian/research/users/phuclh12/Code/minHiWave/eccv_2026/sdxlbase_pixelrushsdxl_sparse_2k_2patches"
    output_dir = "/lustre/scratch/client/movian/research/users/phuclh12/Code/FreeScale/nips_release"
    output_dir = "/lustre/scratch/client/movian/research/users/phuclh12/Code/minHiWave/ducanh_reproduce_pixrush/sdxl_reproduce_pixrush"
    # Option 1: Use directory containing real images
    real_image_dir = "/lustre/scratch/client/movian/research/users/ngannh11/data/laion/train"
    
    # Option 2: Use text file containing image paths (uncomment to use)
    # real_image_dir = "real_image_paths.txt"  # Text file with one image path per line
    
    # Option 3: Create image paths file from directory (uncomment to use)
    # create_image_paths_file(
    #     image_dir="/lustre/scratch/client/movian/research/users/ngannh11/data/laion/train",
    #     output_file="real_image_paths.txt"
    # )
    # real_image_dir = "real_image_paths.txt"
    
    # Check if CUDA is available
    device = 'cuda' if torch.cuda.is_available() else 'cpu'
    print(f"Using device: {device}")
    
    # Memory management tips
    print_memory_usage("Initial")
    if device == 'cuda':
        print("Memory optimization tips:")
        print("- Use smaller batch_size (8-16) if you encounter memory issues")
        print("- Adjust chunk_size (1000-5000) for large datasets")
        print("- Each chunk is cached separately for efficient reprocessing")
        print("- The cache will significantly speed up subsequent runs")
        print("- Memory is automatically cleared during processing")
    
    # Option 1: Run evaluation with chunked processing (recommended for large datasets)
    print("Running evaluation with chunked processing...")
    results = run_evaluation_only(
        output_dir=output_dir,
        real_image_dir=real_image_dir,  # Can be directory or text file
        batch_size=32,  # Reduced batch size for memory efficiency
        device=device,
        use_cache=False,  # Use cached features if available
        chunk_size=3000,  # Process 3k images per chunk to manage memory,
        use_patch=False, # patch-FID,
        real_cache_dir=real_cache_dir
    )
    
    # Option 2: Run evaluation without cache (force recomputation)
    # print("Running evaluation without cache...")
    # results = run_evaluation_only(
    #     output_dir=output_dir,
    #     real_image_dir=real_image_dir,
    #     batch_size=16,  # Reduced batch size for memory efficiency
    #     device=device,
    #     use_cache=False,  # Force recomputation
    #     chunk_size=3000  # Process 3k images per chunk to manage memory
    # )
    
    # Option 3: Clear cache if needed
    # print("Clearing evaluation cache...")
    # clear_evaluation_cache(output_dir)
    
    # Option 4: Force memory cleanup if needed
    # print("Forcing memory cleanup...")
    # force_memory_cleanup()
    
    # Option 2: If you want to run evaluation with real images, uncomment and modify:
    # results = run_evaluation_only(
    #     output_dir="output",
    #     real_image_dir="/lustre/scratch/client/movian/research/users/ngannh11/data/laion/train",
    #     batch_size=32,
    #     device=device
    # )
    
    if results:
        print("\nEvaluation completed successfully!")
        print(f"Results have been saved to '{output_dir}/evaluation_results.json'")
    else:
        print("Evaluation failed or no images found.")

if __name__ == "__main__":
    main()