forked from AIWintermuteAI/aXeleRate
-
Notifications
You must be signed in to change notification settings - Fork 1
/
tests_training_and_inference.py
172 lines (151 loc) · 5.76 KB
/
tests_training_and_inference.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import argparse
import json
from axelerate import setup_training, setup_evaluation
import tensorflow.keras.backend as K
from termcolor import colored
import traceback
import time
def configs(network_type):
classifier = {
"model" : {
"type": "Classifier",
"architecture": "Tiny Yolo",
"input_size": [224,224],
"fully-connected": [],
"labels": [],
"dropout" : 0.5
},
"weights" : {
"full": "",
"backend": None,
"save_bottleneck": True
},
"train" : {
"actual_epoch": 5,
"train_image_folder": "sample_datasets/classifier/imgs",
"train_times": 1,
"valid_image_folder": "sample_datasets/classifier/imgs_validation",
"valid_times": 1,
"valid_metric": "val_accuracy",
"batch_size": 2,
"learning_rate": 1e-4,
"saved_folder": "classifier",
"first_trainable_layer": "",
"augumentation": True
},
"converter" : {
"type": []
}
}
detector = {
"model":{
"type": "Detector",
"architecture": "MobileNet7_5",
"input_size": 224,
"anchors": [0.57273, 0.677385, 1.87446, 2.06253, 3.33843, 5.47434, 7.88282, 3.52778, 9.77052, 9.16828],
"labels": ["aeroplane","person","diningtable","bottle","bird","bus","boat","cow","sheep","train"],
"coord_scale" : 1.0,
"class_scale" : 1.0,
"object_scale" : 5.0,
"no_object_scale" : 1.0
},
"weights" : {
"full": "",
"backend": None
},
"train" : {
"actual_epoch": 5,
"train_image_folder": "sample_datasets/detector/imgs",
"train_annot_folder": "sample_datasets/detector/anns",
"train_times": 1,
"valid_image_folder": "sample_datasets/detector/imgs_validation",
"valid_annot_folder": "sample_datasets/detector/anns_validation",
"valid_times": 1,
"valid_metric": "mAP",
"batch_size": 2,
"learning_rate": 1e-4,
"saved_folder": "detector",
"first_trainable_layer": "",
"augumentation": True,
"is_only_detect" : False
},
"converter" : {
"type": []
}
}
segnet = {
"model" : {
"type": "SegNet",
"architecture": "MobileNet5_0",
"input_size": [224,224],
"n_classes" : 20
},
"weights" : {
"full": "",
"backend": None
},
"train" : {
"actual_epoch": 5,
"train_image_folder": "sample_datasets/segmentation/imgs",
"train_annot_folder": "sample_datasets/segmentation/anns",
"train_times": 4,
"valid_image_folder": "sample_datasets/segmentation/imgs_validation",
"valid_annot_folder": "sample_datasets/segmentation/anns_validation",
"valid_times": 4,
"valid_metric": "val_loss",
"batch_size": 2,
"learning_rate": 1e-4,
"saved_folder": "segment",
"first_trainable_layer": "",
"ignore_zero_class": False,
"augumentation": True
},
"converter" : {
"type": []
}
}
dict = {'all':[classifier,detector,segnet],'classifier':[classifier],'detector':[detector],'segnet':[segnet]}
return dict[network_type]
argparser = argparse.ArgumentParser(description='Test axelerate on sample datasets')
argparser.add_argument(
'-t',
'--type',
default="all",
help='type of network to test:classifier,detector,segnet or all')
argparser.add_argument(
'-a',
'--arch',
type=bool,
default=False,
help='test all architectures?')
argparser.add_argument(
'-c',
'--conv',
type=bool,
default=False,
help='test all converters?')
args = argparser.parse_args()
archs = ['MobileNet7_5']
converters = [""]
errors = []
if args.arch:
archs = ['Full Yolo', 'Tiny Yolo', 'MobileNet1_0', 'MobileNet7_5', 'MobileNet5_0', 'MobileNet2_5', 'SqueezeNet', 'NASNetMobile', 'ResNet50', 'DenseNet121']
if args.conv:
converters = ['k210', 'tflite_fullint', 'tflite_dynamic', 'edgetpu', 'openvino', 'onnx']
for item in configs(args.type):
for arch in archs:
for converter in converters:
try:
item['model']['architecture'] = arch
item['converter']['type'] = converter
print(json.dumps(item, indent=4, sort_keys=False))
model_path = setup_training(config_dict=item)
K.clear_session()
setup_evaluation(item, model_path)
except Exception as e:
traceback.print_exc()
print(colored(str(e), 'red'))
time.sleep(2)
errors.append(item['model']['type'] + " " + arch + " " + converter + " " + str(e))
for error in errors:
print(error)