-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathmodify_data.py
125 lines (102 loc) · 3.59 KB
/
modify_data.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
from os.path import join, exists
from os import listdir, makedirs
from shutil import copyfile
species = [
"blasti",
"bonegl",
"brhkyt",
"cbrtsh",
"cmnmyn",
"gretit",
"hilpig",
"himbul",
"himgri",
"hsparo",
"indvul",
"jglowl",
"lbicrw",
"mgprob",
"rebimg",
"wcrsrt",
]
source_folder = "./train_data/"
destination_folder = "./train/"
def rename_files():
"""
Initially the file names are incosistent. This function
changes the file name to make it more understanding.
Example - for example, DSC_6272.jpg may be changed to 100101.jpg
For bird_specie_counter < 10, in this,
100 -> original image, 1 -> Class Number, 01 -> Image Number
Similarly, for the case if the species counter is greater than 10.
"""
bird_specie_counter = 1
for bird_specie in species:
#
source_image_dir = join(source_folder, bird_specie)
print(source_image_dir)
source_images = listdir(source_image_dir)
print(source_images)
for source_image in source_images:
destination = join(destination_folder, bird_specie)
print(destination)
if bird_specie_counter < 10:
images = 0
for source_image in source_images:
if images < 10:
copyfile(
join(source_image_dir, source_image),
join(
destination,
str(100)
+ str(bird_specie_counter)
+ str(0)
+ str(images)
+ ".jpg",
),
)
elif images >= 10:
copyfile(
join(source_image_dir, source_image),
join(
destination,
str(100)
+ str(bird_specie_counter)
+ str(images)
+ ".jpg",
),
)
images += 1
elif bird_specie_counter >= 10:
images = 0
for source_image in source_images:
if images < 10:
copyfile(
join(source_image_dir, source_image),
join(
destination,
str(10)
+ str(bird_specie_counter)
+ str(0)
+ str(images)
+ ".jpg",
),
)
elif images >= 10:
copyfile(
join(source_image_dir, source_image),
join(
destination,
str(10)
+ str(bird_specie_counter)
+ str(images)
+ ".jpg",
),
)
images += 1
bird_specie_counter += 1
if __name__ == "__main__":
for bird_specie in species:
if not exists(join(destination_folder, bird_specie)):
destination = makedirs(join(destination_folder, bird_specie))
rename_files()