-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfull.py
92 lines (57 loc) · 2.98 KB
/
full.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
from tensorflow_generator import TensorflowGenerator
from products_tree import ProductSet
import json
import sys, getopt, os
def run_tensorflow(product, url, index,datasets=[], epochs=12, depth=1, data_augmentation=False, features=None):
for dataset in datasets:
logpath = "{0}_{1}_{2}epochs_{3}.txt".format(url,dataset, epochs, depth)
tensorflow = TensorflowGenerator(product,epochs, dataset, depth=depth, data_augmentation=data_augmentation)
f2 = open(logpath,"a")
history = "{accuracy}|{validation_accuracy}".format(accuracy="#".join(map(str, tensorflow.history[0])), validation_accuracy="#".join(map(str, tensorflow.history[1])))
f2.write("\r\n{0}: {1} {2} {3} {4} {5} {6}".format(index, tensorflow.accuracy, tensorflow.stop_training, tensorflow.training_time, tensorflow.params, tensorflow.flops, history))
f2.close()
def main(target, min_index=0, max_index=0, filter_indices=[], datasets=None,epochs=12, depth=1, data_augmentation=False, output_folder=""):
productSet = ProductSet(target+".pdt"
)
if not output_folder:
output_folder = "./products/"
if not datasets:
datasets = ["mnist"]
for index, (product, features) in enumerate(productSet.format_products()):
print("product {0}".format(index))
if index >= min_index and (len(filter_indices)==0 or index in filter_indices):
f = open("{0}{1}_{2}.json".format(output_folder, target, index), "w")
str_ = json.dumps(product)
f.write(str_)
f.close()
run_tensorflow(product, target, index, datasets, epochs, depth, data_augmentation=data_augmentation)
if max_index!= 0 and index ==max_index:
break
def init(argv):
input_file = './datasets/1000Products'
depth=1
datasets = ["cifar"]
training_epochs = 600
output_folder = "./products/"
try:
opts, args = getopt.getopt(argv, "hi:n:d:t:", [
"ifile=", "depth=","datasets=","training_epoch="])
except getopt.GetoptError:
pass
print("arguments {}".format(opts))
for opt, arg in opts:
if opt == '-h':
print(
'full.py -i <input_file> -d <datasets> -t <training_epoch>')
sys.exit()
elif opt in ("-d", "--dataset"):
datasets = arg.split(",")
elif opt in ("-i", "--ifile"):
input_file = arg
elif opt in ("-t", "--training_epoch"):
training_epochs = int(arg)
if not os.path.isdir(output_folder):
os.mkdir(output_folder)
main(input_file, datasets=datasets, epochs=training_epochs, depth=depth, output_folder=output_folder)
if __name__ == "__main__":
init(sys.argv[1:])