-
Notifications
You must be signed in to change notification settings - Fork 101
/
organize_flowers17.py
50 lines (41 loc) · 1.44 KB
/
organize_flowers17.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
# organize imports
import os
import glob
import datetime
# print start time
print ("[INFO] program started on - " + str(datetime.datetime.now))
# get the input and output path
input_path = "G:\\workspace\\machine-intelligence\\deep-learning\\flower-recognition\\17flowers\\jpg"
output_path = "G:\\workspace\\machine-intelligence\\deep-learning\\flower-recognition\\dataset\\train"
# get the class label limit
class_limit = 17
# take all the images from the dataset
image_paths = glob.glob(input_path + "\\*.jpg")
# variables to keep track
label = 0
i = 0
j = 80
# flower17 class names
class_names = ["daffodil", "snowdrop", "lilyvalley", "bluebell", "crocus",
"iris", "tigerlily", "tulip", "fritillary", "sunflower",
"daisy", "coltsfoot", "dandelion", "cowslip", "buttercup",
"windflower", "pansy"]
# change the current working directory
os.chdir(output_path)
# loop over the class labels
for x in range(1, class_limit+1):
# create a folder for that class
os.system("mkdir " + class_names[label])
# get the current path
cur_path = output_path + "\\" + class_names[label] + "\\"
# loop over the images in the dataset
for image_path in image_paths[i:j]:
original_path = image_path
image_path = image_path.split("\\")
image_path = image_path[len(image_path)-1]
os.system("copy " + original_path + " " + cur_path + image_path)
i += 80
j += 80
label += 1
# print end time
print ("[INFO] program ended on - " + str(datetime.datetime.now))