-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_splits.py
More file actions
84 lines (60 loc) · 3.14 KB
/
create_splits.py
File metadata and controls
84 lines (60 loc) · 3.14 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
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
import os
import shutil
source_dir = './fid_data/generated_images_KD' # Path to your generated_images directory
dest_dir = './fid_data/combined_generated_images_KD' # Path to the destination directory
if not os.path.exists(dest_dir):
os.makedirs(dest_dir)
for class_dir in os.listdir(source_dir):
class_dir_path = os.path.join(source_dir, class_dir)
if os.path.isdir(class_dir_path): # Make sure it's a directory
for filename in os.listdir(class_dir_path):
file_path = os.path.join(class_dir_path, filename)
# Ensure we're copying files (not directories)
if os.path.isfile(file_path):
# Prepend the class ID to the filename
new_filename = f"{class_dir}_{filename}"
shutil.copy(file_path, os.path.join(dest_dir, new_filename))
print("All images have been copied and renamed in:", dest_dir)
# import os
# import shutil
# import random
# source_dir = './data/cifar10-64/test' # Path to the test directory of CIFAR-10
# dest_dir = './sampled_cifar10_images' # Path to the destination directory
# images_per_class = 1024 # Number of images to sample per class
# if not os.path.exists(dest_dir):
# os.makedirs(dest_dir)
# for class_dir in os.listdir(source_dir):
# class_dir_path = os.path.join(source_dir, class_dir)
# if os.path.isdir(class_dir_path):
# all_filenames = os.listdir(class_dir_path)
# sampled_filenames = random.sample(all_filenames, min(images_per_class, len(all_filenames)))
# for filename in sampled_filenames:
# file_path = os.path.join(class_dir_path, filename)
# # Ensure we're moving files (not directories)
# if os.path.isfile(file_path):
# # Prepend the class ID to the filename
# new_filename = f"{class_dir}_{filename}"
# shutil.move(file_path, os.path.join(dest_dir, new_filename))
# print("Sampled images have been moved to:", dest_dir)
# import os
# import shutil
# import random
# source_dir = './data/cifar10-64/train' # Path to the test directory of CIFAR-10
# dest_dir = './sampled_cifar10_images' # Path to the destination directory
# images_per_class = 1024 # Number of images to sample per class
# if not os.path.exists(dest_dir):
# os.makedirs(dest_dir)
# for class_dir in os.listdir(source_dir):
# class_dir_path = os.path.join(source_dir, class_dir)
# class_dest_dir = os.path.join(dest_dir, class_dir)
# if not os.path.exists(class_dest_dir):
# os.makedirs(class_dest_dir)
# if os.path.isdir(class_dir_path):
# all_filenames = os.listdir(class_dir_path)
# sampled_filenames = random.sample(all_filenames, min(images_per_class, len(all_filenames)))
# for filename in sampled_filenames:
# file_path = os.path.join(class_dir_path, filename)
# # Ensure we're moving files (not directories)
# if os.path.isfile(file_path):
# shutil.move(file_path, os.path.join(class_dest_dir, filename))
# print("Sampled images have been moved to their respective class folders in:", dest_dir)