-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathcreate_eval_data.py
More file actions
53 lines (41 loc) · 1.74 KB
/
create_eval_data.py
File metadata and controls
53 lines (41 loc) · 1.74 KB
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
import os
import shutil
import sys
def copy_images(source_dir, destination_dir, file_list):
"""
Copies images listed in a file from a source directory to a destination directory.
Parameters:
- source_dir: The directory where the images are located.
- destination_dir: The directory where the images will be copied to.
- file_list: A file containing the list of image file names to copy.
"""
# Create the destination directory if it doesn't exist
if not os.path.exists(destination_dir):
os.makedirs(destination_dir)
# Open the file containing the list of images to copy
with open(file_list, 'r') as file:
for line in file:
# Remove any trailing whitespace or newline characters
image_name = line.strip()
# Define the source and destination file paths
source_file = os.path.join(source_dir, image_name)
destination_file = os.path.join(destination_dir, image_name)
# Check if the source file exists before attempting to copy
if os.path.exists(source_file):
# Copy the file to the destination directory
shutil.copy(source_file, destination_file)
else:
print(f"File {image_name} not found in source directory.")
def main():
if len(sys.argv) != 4:
print("Usage: python script.py <source_dir> <destination_dir> <file_list>")
sys.exit(1)
source_dir = sys.argv[1]
destination_dir = sys.argv[2]
file_list = sys.argv[3]
copy_images(source_dir, destination_dir, file_list)
if __name__ == "__main__":
"""
python scripts/create_eval_data.py /mnt/disks/datasets/celeba-hq ./eval_data ./data/celebahqvalidation_jpg.txt
"""
main()