-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconfig.py
More file actions
112 lines (91 loc) · 5.02 KB
/
config.py
File metadata and controls
112 lines (91 loc) · 5.02 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import os
from typing import Dict,List
import json
class Config:
# static path property
ProjectRootFold = os.path.dirname(os.path.abspath(__file__))
# bench data save-path
BenchmarkDataSavePath_cold_run=os.path.join(ProjectRootFold, "Benchmark/timecost/data-cold_run.json")
BenchmarkDataSavePath_hot_run=os.path.join(ProjectRootFold, "Benchmark/timecost/data-hot_run.json")
BenchmarkDataAnalyzeSaveFold=os.path.join(ProjectRootFold, "Benchmark/images/")
# onnx-model save-path
OnnxSaveFold = os.path.join(ProjectRootFold, "Onnxs")
TVMLibSaveFold = os.path.join(ProjectRootFold, "RunLib")
# model-functions text save-path
RawModelFunctionsTextSaveFold = os.path.join(ProjectRootFold, "ModelFuntionsText/raw")
ChildsModelFunctionsTextSaveFold= os.path.join(ProjectRootFold, "ModelFuntionsText/childs")
# model-functions Python-file save-path
RawModelFunctionsPythonSaveFold = os.path.join(ProjectRootFold, "ModelFuntionsPython/raw")
ChildsModelFunctionsPythonSaveFold= os.path.join(ProjectRootFold, "ModelFuntionsPython/childs")
TestDataCount = 10
@staticmethod
def RawModelFunctionsTextSavePathName(model_name)->str:
'''
name is given when you use raw model functions text from disk, you may create this file by print-copy. Return "$project_path/ModelFuntionsText/raw/$model_name.txt"
'''
return os.path.join(Config.RawModelFunctionsTextSaveFold,model_name+".txt")
@staticmethod
def RawModelFunctionsPythonSavePathName(model_name)->str:
'''
name is given when you use raw model functions Python-file from disk, you may create this file by print-copy. Return "$project_path/ModelFuntionsPython/raw/$model_name.py"
'''
return os.path.join(Config.RawModelFunctionsPythonSaveFold,model_name+".py")
@staticmethod
def ModelParamsFile(model_name)->Dict[int,List[dict]]:
'''
return convert "$project_path/ModelFuntionsText/childs/$model_name/params.json" to dict
'''
jsonFilePath=os.path.join(Config.ChildModelFunctionsTextSaveFold(model_name),"params.json")
if not os.path.exists(jsonFilePath):
return None
with open(jsonFilePath,"r") as fp:
try:
return json.load(fp)
except Exception as ex:
print("error:",ex)
return None
@staticmethod
def ChildModelFunctionsPythonSavePathName(model_name)->str:
'''
name is given when you use child-model functions Python-file from disk, you may create this file by print-copy. Return "$project_path/ModelFuntionsPython/childs/$model_name.py"
'''
return os.path.join(Config.ChildsModelFunctionsPythonSaveFold,model_name+".py")
@staticmethod
def ChildModelFunctionsTextSaveFold(model_name)->str:
'''
name is given when you use child-model functions Text-file fold from disk, you may create this file by print-copy. Return "$project_path/ModelFuntionsText/childs/$model_name/"
'''
return os.path.join(Config.ChildsModelFunctionsTextSaveFold,model_name)
@staticmethod
def ModelSavePathName(name) -> str:
'''
name is given when you create the data. Return "$project_path/Onnxs/$name/$name.onnx"
'''
os.makedirs(os.path.join(Config.OnnxSaveFold, name),exist_ok=True)
return os.path.join(Config.OnnxSaveFold, name, name+".onnx")
@staticmethod
def ChildModelSavePathName(name,idx) -> str:
'''
name is given when you create the data. Return "$project_path/Onnxs/$name/childs/idx/$name.onnx", "$project_path/RunLib/$target/$name/$idx/$name-$idx-params.json"
'''
os.makedirs(os.path.join(Config.OnnxSaveFold, name,"childs",str(idx)),exist_ok=True)
return os.path.join(Config.OnnxSaveFold, name,"childs",str(idx), "{}-{}.onnx".format(name,str(idx))),os.path.join(Config.OnnxSaveFold, name,"childs",str(idx), "{}-{}-params.json".format(name,str(idx)))
@staticmethod
def TvmLibSavePathByName(name, target, idx: int=-1) -> str:
'''
name is given when you create the data. Return "$project_path/RunLib/$target/$name/$name-$idx.tar", "$project_path/RunLib/$target/$name/$idx/$name-$idx-input_shape.json"
'''
if idx>=0:
fold=os.path.join(Config.TVMLibSaveFold,target,name,"childs",str(idx))
os.makedirs(fold,exist_ok=True)
return os.path.join(fold, "{}-{}.tar".format(name,str(idx))),os.path.join(fold, "{}-{}-input_shape.json".format(name,str(idx)))
else:
fold=os.path.join(Config.TVMLibSaveFold,target,name,"raw")
os.makedirs(fold,exist_ok=True)
return os.path.join(fold, "{}.tar".format(name)),os.path.join(fold, "{}-input_shape.json".format(name))
@staticmethod
def ModelSaveDataPathName(name) -> str:
'''
name is given when you create the data. Return "$project_path/Onnxs/$name/data.json"
'''
return os.path.join(Config.OnnxSaveFold, name, "data.json")