-
Notifications
You must be signed in to change notification settings - Fork 4
/
modelInfo.py
66 lines (52 loc) · 2.53 KB
/
modelInfo.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
import sys
sys.path.append("../")
sys.path.append("../..")
import os
from KETIToolDL import setting
# This class includes a general model generation/selection information.
class ModelFileManager():
""" Create full file paths of machine learning models. This class can be used for both training and inference.
"""
def __init__(self ,modelInfoList = setting.myModelInfoList):
""" set modelInfoList
If there is no input related to modelInfoList, the information of the setting file is used.
Therefore, setting.py file can be used to declare a general model information.
:param modelInfoList: modelInfo for making full-ModelFilePaths
:type modelInfoList: json dictionary
example
>>> myModelRootPath = ["c:","Users", "bunny", "Code_CLUST", "KETIToolDL","DL", "Models"]
>>> myModelInfoList = {
"brits":{
"modelRootPath": myModelRootPath,
"modelInfoPath": ["brits"],
"modelFileNames":['model.json', 'model.pth']
}
}
"""
self.modelInfoList = modelInfoList
def getModelFilePath(self, trainDataPathList, method):
""" get fullModelFilePath
Ths function makes fullModelFilePath list.
trainDataPathList and other paths obtained by method can be used for creating fullModelFilePath.
:param trainDataPathList: It includes train data information to generate model path
:type trainDataPathList: list of str
:param method: train method
:type method: str
example
>>> from KETIToolDL import modelInfo
>>> MI = modelInfo.ModelFileManager()
>>> trainDataPathList =['DBName', 'MSName', 'columnName' ]
>>> trainMethod ='brits'
>>> modelFilePath = MI.getModelFilePath(trainDataPathList, self.trainMethod)
"""
modelInfo = self.modelInfoList[method]
modelFullPath =modelInfo['modelRootPath']+modelInfo['modelInfoPath']+trainDataPathList
modelFolderPath=''
for addfolder in modelFullPath:
modelFolderPath = os.path.join(modelFolderPath, addfolder)
if not os.path.exists(modelFolderPath):
os.makedirs(modelFolderPath)
modelFilePath=[]
for i, model_name in enumerate(modelInfo['modelFileNames']):
modelFilePath.append(os.path.join(modelFolderPath, model_name))
return modelFilePath