Download eval_code/eval_example.py from phuckstnk63/abcxyz: direct link, hf CLI and curl.
- Browser
- Download file 3.96 kB
-
https://huggingface.co/datasets/phuckstnk63/abcxyz/resolve/main/eval_code/eval_example.py
- Command line
-
hf download hf://datasets/phuckstnk63/abcxyz/eval_code/eval_example.py
-
curl -L -o eval_example.py https://huggingface.co/datasets/phuckstnk63/abcxyz/resolve/main/eval_code/eval_example.py
3.96 kB
| #!/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() |