-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnew_config_data.py
More file actions
95 lines (86 loc) · 3.34 KB
/
new_config_data.py
File metadata and controls
95 lines (86 loc) · 3.34 KB
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
r"""
--------------------------------------------------------------------------------
-- _____ ______ _____ --
-- |_ _| | ____|/ ____| --
-- | | _ __ | |__ | (___ --
-- | | | '_ \| __| \___ \ Institute of Embedded Systems --
-- _| |_| | | | |____ ____) | Zurich University of Applied Sciences --
-- |_____|_| |_|______|_____/ 8401 Winterthur, Switzerland --
--------------------------------------------------------------------------------
--! @file
--! @brief Configuration Reader Class to facilitate usage with json file
--!
--! @author vore
--! @date 18-11-2025
--
--------------------------------------------------------------------------------
"""
import json
import os
class ConfigReader:
name: str
data_file: str
inputs: int
bit_width: int
precision: int
runs: int
layers: list
parallel_elements: int
signed_flag: bool
max_str_len: int
weigth_widths: list
weight_width: int
def __init__(self, config_path=None):
if config_path is not None:
self.read_config(config_path)
def read_config(self, config_path):
with open(config_path) as config_file:
config = json.load(config_file)
self.name = config["name"]
self.data_file = config["data_file"]
self.inputs = config["inputs"]
self.bit_width = config["bit_width"]
self.data_width = config["width"]
self.precision = config["precision"]
self.parallel_elements = config["parallel_elements"]
self.signed_flag = config["signed_flag"]
self.layers = config["layers"]
self.max_str_len = 60
if "runs" in config:
self.runs = config["runs"]
else:
self.runs = 1
self.weight_width = config["weight_width"]
def get_layer_data(self):
counter = 0
path = os.path.dirname(os.path.abspath(__file__))
layer_sizes = [layer["size"] for layer in self.layers]
kernel_sizes = [layer.get("kernel_size", 1) for layer in self.layers]
activations = ["r" if layer["activation"] == "relu" else "l" for layer in self.layers]
special_layers = ["f" if "flatten" in layer else "n" for layer in self.layers]
layer_types = []
paths = []
for _, layer in enumerate(self.layers):
if layer["type"] == "TopK":
"""do nothing"""
elif layer["type"] == "dense":
layer_types.append("d")
paths.append(path + "/simulation/data/threshx/")
elif layer["type"] == "thresh":
layer_types.append("t")
paths.append(path + "/simulation/data/thresh" + str(counter) + "/")
counter += 1
counter = 0
input_width = [layer["input_width"] for layer in self.layers]
output_width = [layer["output_width"] for layer in self.layers]
return {
"ls": layer_sizes,
"ks": kernel_sizes,
"act": activations,
"sp": special_layers,
"lt": layer_types,
"ip": input_width,
"op": output_width,
"paths": paths,
"weight_width": self.weight_width,
}