-
Notifications
You must be signed in to change notification settings - Fork 0
/
model_config.py
124 lines (103 loc) · 3.55 KB
/
model_config.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
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
113
114
115
116
117
118
119
120
121
122
123
124
import os
import time
import torch
import config
class BaseConfig:
"""
基础模型参数
"""
def __init__(self,
name: str,
epochs: int,
batch_size: int,
learning_rate,
training,
gpu,
model_load_path,
index_column,
label_regression,
label_classify,
train_from_scratch: bool,
):
self.model_name = name
time_strftime = time.strftime("%Y%m%d%H%M")
model_save_path = os.path.join(config.MODEL_FILE_PATH, self.model_name, time_strftime)
self.model_save_path = os.path.join(model_save_path, f'{self.model_name}.pt')
if model_load_path:
self.model_load_path = model_load_path
else:
self.model_load_path = self.model_save_path
self.model_log_path = model_save_path
if training:
os.makedirs(model_save_path, exist_ok=True)
self.epochs = epochs
self.batch_size = batch_size
self.learning_rate = learning_rate
self.prediction_name = 'pred'
self.gpu = gpu
self.training = training
self.features = []
self.index_column = index_column
self.label_regression = label_regression
self.label_classify = label_classify
self.train_from_scratch = train_from_scratch
if gpu and torch.cuda.is_available():
self.device = torch.device('cuda')
else:
self.device = torch.device('cpu')
def set_features(self, features: list):
self.features = features.copy()
if self.label_regression in self.features:
self.features.remove(self.label_regression)
for label_classify in self.label_classify:
if label_classify in self.features:
self.features.remove(label_classify)
class ImageConfig(BaseConfig):
def __init__(self,
name: str = 'Model-Image',
epochs=100,
batch_size=100,
learning_rate=0.01,
training=True,
gpu=True,
model_load_path=None,
train_from_scratch=False,
):
super(ImageConfig, self).__init__(
name,
epochs,
batch_size,
learning_rate,
training,
gpu,
model_load_path,
index_column='patient ID',
label_regression='CST',
label_classify=['IRF', 'SRF', 'PED', 'HRF'],
train_from_scratch=train_from_scratch,
)
self.img_column = 'processed_path'
class CSVConfig(BaseConfig):
def __init__(self,
name: str = 'Model-CSV',
epochs=100,
batch_size=100,
learning_rate=0.01,
training=True,
gpu=True,
model_load_path=None,
train_from_scratch=False,
):
super(CSVConfig, self).__init__(
name,
epochs,
batch_size,
learning_rate,
training,
gpu,
model_load_path,
index_column='patient ID',
label_regression='VA',
label_classify=['continue injection'])
self.set_features(['gender', 'age', 'diagnosis', 'anti-VEGF', 'L0R1', 'preVA', 'preCST',
'preIRF', 'preSRF', 'prePED', 'preHRF', 'CST', 'IRF', 'SRF', 'PED', 'HRF'])