-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen_oneshot.py
85 lines (55 loc) · 2.34 KB
/
gen_oneshot.py
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
import os
import random
import shutil
source_folder = "/home/anhhoang/New_Term/AlignedReID/datamica/20191104_all/query/"
destination_folder ="/home/anhhoang/New_Term/AlignedReID/datamica/20191104_all_one/query/"
if not os.path.exists(destination_folder):
os.makedirs(destination_folder)
else:
for filename in os.listdir(destination_folder):
file_path = os.path.join(destination_folder, filename)
try:
if os.path.isfile(file_path):
os.unlink(file_path)
except Exception as e:
print(f"Cant delete {file_path}: {e}")
image_files = [f for f in os.listdir(source_folder) if f.endswith('.jpg')]
image_dict = {}
for image_file in image_files:
parts = image_file.split('_')
x = int(parts[0].replace("c", ""))
if x not in image_dict:
image_dict[x] = []
image_dict[x].append(image_file)
for x, images_for_x in image_dict.items():
random_image = random.choice(images_for_x)
source_path = os.path.join(source_folder, random_image)
destination_path = os.path.join(destination_folder, random_image)
shutil.copy(source_path, destination_path)
print("Succes!")
source_folder = "/home/anhhoang/New_Term/AlignedReID/datamica/20191104_all/gallery/"
destination_folder ="/home/anhhoang/New_Term/AlignedReID/datamica/20191104_all_one/gallery/"
if not os.path.exists(destination_folder):
os.makedirs(destination_folder)
else:
for filename in os.listdir(destination_folder):
file_path = os.path.join(destination_folder, filename)
try:
if os.path.isfile(file_path):
os.unlink(file_path)
except Exception as e:
print(f"Cant delete {file_path}: {e}")
image_files = [f for f in os.listdir(source_folder) if f.endswith('.jpg')]
image_dict = {}
for image_file in image_files:
parts = image_file.split('_')
x = int(parts[0].replace("c", ""))
if x not in image_dict:
image_dict[x] = []
image_dict[x].append(image_file)
for x, images_for_x in image_dict.items():
random_image = random.choice(images_for_x)
source_path = os.path.join(source_folder, random_image)
destination_path = os.path.join(destination_folder, random_image)
shutil.copy(source_path, destination_path)
print("Succes!")