-
Notifications
You must be signed in to change notification settings - Fork 0
/
clean_queue.py
79 lines (65 loc) · 2.33 KB
/
clean_queue.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
import json
import numpy as np
import pandas as pd
workloads = ["max_pool2d", "avg_pool2d", "dense", "conv2d"]
for workload in workloads:
print("cleaning up "+workload+" sample set")
if workload == "conv2d":
workload_path = "conv_layer_config.json"
elif workload == "dense":
workload_path = "dense_layer_config.json"
elif workload == "avg_pool2d":
workload_path = "avg_pool_layer_config.json"
elif workload == "max_pool2d":
workload_path = "max_pool_layer_config.json"
list_features = {
"input shape" : ["N_I", "H_I", "W_I", "C_I"],
"output shape" : ["N_O", "H_O", "W_O", "C_O"],
}
features = ["output dtype", "compute dtype"]
if workload in ["avg_pool2d", "max_pool2d", "conv2d"]:
features += ["padding"]
list_features.update({
"strides" : ["strides_0", "strides_1"],
})
if "pool" in workload:
list_features.update({
"pool_size" : ["pool_0", "pool_1"],
})
if "dense" in workload:
list_features.update({
"input shape" : ["N_I", "H_I"],
"output shape" : ["N_O", "H_O"],
})
if "conv2d" == workload:
features += ["filters", "groups"]
list_features.update({
"kernel" : ["kernel_0", "kernel_1"],
"dilation" : ["dilation_0", "dilation_1"],
})
with open(workload_path, "r") as file:
configs = json.load(file)
print("json file has been read")
df = pd.DataFrame.from_dict(configs, orient='index')
print("dataframe generated")
print("full workset size", len(df))
print("expand list features")
for name, heads in list_features.items():
print(name, "\t:\t", heads)
split_df = pd.DataFrame(df[name].tolist(), columns=heads)
split_df.index = df.index
df = pd.concat([df, split_df], axis=1)
features += heads
df = df.drop_duplicates(subset=features)
print("after duplicate removal", len(df))
for name, heads in list_features.items():
df = df.drop(heads, axis=1)
df = df.T
print("writting back to JSON")
target_path = workload_path.replace(".json", "_clean.json")
raw_json = df.to_json()
with open(target_path, "w") as file:
file.write(raw_json)
print(workload + " done...")
print()
print("done")