forked from eliberis/uNAS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_generate_tf_save_model_sc_nq.py
41 lines (31 loc) · 993 Bytes
/
test_generate_tf_save_model_sc_nq.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
import pickle
# Load
with open('artifacts/cnn_speech_commands/example_cnn_speech_commands_struct_pru_agingevosearch_state.pickle', 'rb') as f:
EvaluatedPoint = pickle.load(f)
print("------------------------------")
print("len of EvaluatedPoint:",len(EvaluatedPoint))
print("-----------------------------")
'''
@dataclass
class EvaluatedPoint:
point: ArchitecturePoint
val_error: float
test_error: float
resource_features: List[Union[int, float]]
'''
import numpy as np
import tensorflow as tf
from architecture import Architecture
from cnn import CnnSearchSpace
from resource_models.models import model_size, peak_memory_usage
output_dir = "tmp/tflite"
input_shape = (49, 40, 1)
num_classes = 10
def convert_to_keras(arch, output_file):
model = arch.to_keras_model(input_shape, num_classes)
model.summary()
model.save(output_file)
#convert
archid = 1327
arch = EvaluatedPoint[archid].point.arch
convert_to_keras(arch, output_file=f"{output_dir}/")