-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_datasets.py
88 lines (80 loc) · 4.05 KB
/
gen_datasets.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
import shutil
from GenLabelNoiseTS.GenLabelNoiseTS import *
rootPath = './data/'
def main():
noRuns = 10
initPath = 'init_param_file.csv'
nameDataDir = Path(rootPath)
namesDir = (nameDataDir / 'TwoClass', nameDataDir / 'FiveClass', nameDataDir / 'TenClass')
if os.path.isdir(nameDataDir):
print('Dir data/ already exist !')
print('Do you want delete dir data/ ? [y(Yes) or n(No)]')
answer = input()
while answer != 'y' and answer != 'n':
answer = input()
if answer == 'y':
shutil.rmtree(nameDataDir)
elif answer == 'n':
print('Error Dir data/ already exist !')
else:
answer = 'y'
if answer == 'y':
os.mkdir(nameDataDir, 0o755)
noiseArray = [round(i, 2) for i in np.arange(0, 1.05, 0.05)]
l = 0
lMax = (len(namesDir) * 10 * len(noiseArray)) + (10 * len(noiseArray)) - 1
print('PROGRESS BAR GENERATE DATA :')
for i in namesDir:
os.mkdir(i, 0o755)
for j in range(noRuns):
os.mkdir(i / ('Run' + str(j + 1)), 0o755)
if i == nameDataDir / 'TwoClass':
generator = GenLabelNoiseTS(filename="dataset.h5", dir=i / ('Run' + str(j + 1) + '/'),
pathInitFile=initPath, classList=('Corn', 'Corn_Ensilage'),
csv=True, verbose=False)
elif i == nameDataDir / 'FiveClass':
generator = GenLabelNoiseTS(filename="dataset.h5", dir=i / ('Run' + str(j + 1) + '/'),
pathInitFile=initPath,
classList=('Corn', 'Corn_Ensilage', 'Sorghum', 'Sunflower', 'Soy'),
csv=True, verbose=False)
a = {'Corn': 'Corn_Ensilage', 'Corn_Ensilage': 'Sorghum', 'Sorghum': 'Sunflower',
'Sunflower': 'Soy',
'Soy': 'Corn'}
elif i == nameDataDir / 'TenClass':
generator = GenLabelNoiseTS(filename="dataset.h5", dir=i / ('Run' + str(j + 1) + '/'),
pathInitFile=initPath,
classList=('Corn', 'Corn_Ensilage', 'Sorghum', 'Sunflower', 'Soy',
'Wheat', 'Rapeseed', 'Barley',
'Evergreen', 'Decideous'),
csv=True, verbose=False)
for k in noiseArray:
generator.getNoiseDataXY(k)
printProgressBar(l, lMax)
if i == nameDataDir / 'FiveClass':
generator.getNoiseDataXY(k, a)
l += 1
l += 1
generator.getTestData()
print('DONE !')
# Print iterations progress
def printProgressBar(iteration, total, prefix='', suffix='', decimals=1, length=100, fill='█', printEnd="\r"):
"""
Call in a loop to create terminal progress bar
@params:
iteration - Required : current iteration (Int)
total - Required : total iterations (Int)
prefix - Optional : prefix string (Str)
suffix - Optional : suffix string (Str)
decimals - Optional : positive number of decimals in percent complete (Int)
length - Optional : character length of bar (Int)
fill - Optional : bar fill character (Str)
printEnd - Optional : end character (e.g. "\r", "\r\n") (Str)
"""
percent = ("{0:." + str(decimals) + "f}").format(100 * (iteration / float(total)))
filledLength = int(length * iteration // total)
bar = fill * filledLength + '-' * (length - filledLength)
print('\r%s |%s| %s%% %s' % (prefix, bar, percent, suffix), end=printEnd)
# Print New Line on Complete
if iteration == total:
print()
if __name__ == "__main__": main()