-
Notifications
You must be signed in to change notification settings - Fork 1
/
database.py
168 lines (138 loc) · 6.7 KB
/
database.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
from datetime import datetime
from sqlalchemy import PrimaryKeyConstraint
from sqlalchemy.sql.schema import ForeignKey
from app import db
class Dsample(db.Model):
# Sample Details
__tablename__ = "Dsample"
sample_id = db.Column(db.Integer, primary_key=True, autoincrement=True)
dataset_name = db.Column(db.String(32), nullable=False, index=True)
video_id = db.Column(db.String(32), nullable=False, index=True)
clip_id = db.Column(db.String(32), nullable=False, index=True)
video_path = db.Column(db.String(128), nullable=False)
text = db.Column(db.String(1024), nullable=False)
data_mode = db.Column(db.String(8), index=True) # 0 -- train, 1 -- valid, 2 -- test
label_value = db.Column(db.Float, index=True) # regression label
annotation = db.Column(db.String(16), index=True, default='-') # class label in string
label_T = db.Column(db.Float) # text regression label
label_A = db.Column(db.Float) # audio regression label
label_V = db.Column(db.Float) # video regression label
__table_args__ = (db.UniqueConstraint('dataset_name', 'video_id', 'clip_id', name='ix_dataset_video_clip'),)
def __repr__(self):
return str(self.__dict__)
class Result(db.Model):
# final result of a task
__tablename__ = "Result"
result_id = db.Column(db.Integer, primary_key=True, autoincrement=True)
dataset_name = db.Column(db.String(32), nullable=False, index=True)
model_name = db.Column(db.String(32), nullable=False, index=True)
# Tune, Normal
# is_tuning = db.Column(db.String(8), index=True)
is_tune = db.Column(db.Boolean, nullable=False, index=True)
custom_feature = db.Column(db.Boolean, nullable=False, index=True)
created_at = db.Column(db.DateTime, default=datetime.now(), index=True)
args = db.Column(db.String(2048), nullable=False, default="{}")
save_model_path = db.Column(db.String(128))
# final test results
loss_value = db.Column(db.Float, nullable=False, index=True)
accuracy = db.Column(db.Float, nullable=False, index=True)
f1 = db.Column(db.Float, nullable=False, index=True)
mae = db.Column(db.Float, nullable=False, index=True)
corr = db.Column(db.Float, nullable=False, index=True)
description = db.Column(db.String(128))
def get_id(self):
return str(self.result_id)
def __repr__(self):
return str(self.__dict__)
class SResults(db.Model):
# results for each sample
__tablename__ = "SResults"
result_id = db.Column(db.Integer, nullable=False)
sample_id = db.Column(db.Integer, nullable=False)
label_value = db.Column(db.String(16), nullable=False)
predict_value = db.Column(db.String(16), nullable=False)
predict_value_r = db.Column(db.Float, nullable=False)
__table_args__ = (
PrimaryKeyConstraint("result_id", "sample_id"),
)
def __repr__(self):
return str(self.__dict__)
class EResult(db.Model):
# results for each epoch
__tablename__ = "EResult"
result_id = db.Column(db.Integer, nullable=False)
epoch_num = db.Column(db.Integer, nullable=False)
results = db.Column(db.String(1024), nullable=False)
# json {"train": {"loss": ***, "accuracy": ***, "f1": ***}, "valid": {***}}
__table_args__ = (
PrimaryKeyConstraint("result_id", "epoch_num"),
)
def __repr__(self):
return str(self.__dict__)
class Task(db.Model):
__tablename__ = "Task"
task_id = db.Column(db.Integer, primary_key=True, autoincrement=True)
dataset_name = db.Column(db.String(32), nullable=False, index=True)
model_name = db.Column(db.String(32), nullable=False, index=True)
task_type = db.Column(db.Integer, nullable=False, index=True) # 0 - 机器标注 1 - 模型训练,2 - 模型调参,3 - 模型测试,4 - 特征抽取
task_pid = db.Column(db.Integer, nullable=False, index=True)
state = db.Column(db.Integer, nullable=False, index=True) # 0 -- 运行中,1 -- 已完成,2 -- 运行出错 3 -- 运行终止
start_time = db.Column(
db.DateTime, default=datetime.now(), index=True)
end_time = db.Column(
db.DateTime, default=datetime.now())
message = db.Column(db.String(32))
def __repr__(self):
return str(self.__dict__)
class User(db.Model):
__tablename__ = "User"
user_id = db.Column(db.Integer, primary_key=True, autoincrement=True)
user_name = db.Column(db.String(64), nullable=False, index=True, unique=True)
password = db.Column(db.String(255), nullable=False)
is_admin = db.Column(db.Boolean, default=True, server_default='0')
def __repr__(self):
return str(self.__dict__)
class Annotation(db.Model):
__tablename__ = "Annotation"
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
user_name = db.Column(db.String(64), ForeignKey("User.user_name"), nullable=False)
dataset_name = db.Column(db.String(32), nullable=False)
video_id = db.Column(db.String(32), nullable=False)
clip_id = db.Column(db.String(32), nullable=False)
label_M = db.Column(db.Float)
label_T = db.Column(db.Float)
label_A = db.Column(db.Float)
label_V = db.Column(db.Float)
__table_args__ = (db.ForeignKeyConstraint(['dataset_name', 'video_id', 'clip_id'],
['Dsample.dataset_name', 'Dsample.video_id', 'Dsample.clip_id']),
db.UniqueConstraint('user_name', 'dataset_name', 'video_id', 'clip_id', name='ix_user_dataset_video_clip',),
db.Index('ix_user_dataset_labelM', 'user_name', 'dataset_name', 'label_M'),
db.Index('ix_user_dataset_labelT', 'user_name', 'dataset_name', 'label_T'),
db.Index('ix_user_dataset_labelA', 'user_name', 'dataset_name', 'label_A'),
db.Index('ix_user_dataset_labelV', 'user_name', 'dataset_name', 'label_V'),
)
def __repr__(self):
return str(self.__dict__)
class Feature(db.Model):
__tablename__ = "Feature"
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
dataset_name = db.Column(db.String(32), nullable=False)
feature_name = db.Column(db.String(32), nullable=False)
feature_T = db.Column(db.String(128))
feature_A = db.Column(db.String(128))
feature_V = db.Column(db.String(128))
feature_path = db.Column(db.String(256), nullable=False)
description = db.Column(db.String(256))
__table_args__ = (
db.UniqueConstraint('dataset_name', 'feature_name', 'feature_T', 'feature_A', 'feature_V', name='ix_dataset_feature_T_A_V',),
)
# ALL_TABLES = {
# 'Dsample': Dsample,
# 'Result': Result,
# 'SResults': SResults,
# 'EResult': EResult,
# 'Task': Task,
# 'User': User,
# 'Annotation': Annotation,
# 'Feature': Feature,
# }