|
@@ -21,7 +21,7 @@ np.random.seed(42) # NumPy随机种子
|
|
app = Flask('tf_lstm_train——service')
|
|
app = Flask('tf_lstm_train——service')
|
|
|
|
|
|
current_dir = os.path.dirname(os.path.abspath(__file__))
|
|
current_dir = os.path.dirname(os.path.abspath(__file__))
|
|
-with open(os.path.join(current_dir, 'lstm.yaml'), 'r', encoding='utf-8') as f:
|
|
|
|
|
|
+with open(os.path.join(current_dir, 'transformer.yaml'), 'r', encoding='utf-8') as f:
|
|
global_config = yaml.safe_load(f) # 只读的全局配置
|
|
global_config = yaml.safe_load(f) # 只读的全局配置
|
|
|
|
|
|
@app.before_request
|
|
@app.before_request
|
|
@@ -41,7 +41,7 @@ def update_config():
|
|
g.trans = TransformerHandler(logger, current_config)
|
|
g.trans = TransformerHandler(logger, current_config)
|
|
|
|
|
|
|
|
|
|
-@app.route('/tf_lstm_training', methods=['POST'])
|
|
|
|
|
|
+@app.route('/tf_transformer_training', methods=['POST'])
|
|
def model_training_lstm():
|
|
def model_training_lstm():
|
|
# 获取程序开始时间
|
|
# 获取程序开始时间
|
|
start_time = time.time()
|
|
start_time = time.time()
|
|
@@ -60,7 +60,7 @@ def model_training_lstm():
|
|
# ------------ 训练模型,保存模型 ------------
|
|
# ------------ 训练模型,保存模型 ------------
|
|
# 1. 如果是加强训练模式,先加载预训练模型特征参数,再预处理训练数据
|
|
# 1. 如果是加强训练模式,先加载预训练模型特征参数,再预处理训练数据
|
|
# 2. 如果是普通模式,先预处理训练数据,再根据训练数据特征加载模型
|
|
# 2. 如果是普通模式,先预处理训练数据,再根据训练数据特征加载模型
|
|
- model = trans.train_init() if trans.opt.Model['add_train'] else trans.get_transformer_model(trans.opt, time_series=args['time_series'], lstm_type=1)
|
|
|
|
|
|
+ model = trans.train_init() if trans.opt.Model['add_train'] else trans.get_transformer_model(trans.opt, time_series=args['time_series'])
|
|
if trans.opt.Model['add_train']:
|
|
if trans.opt.Model['add_train']:
|
|
if model:
|
|
if model:
|
|
feas = json.loads(trans.model_params)['features']
|
|
feas = json.loads(trans.model_params)['features']
|
|
@@ -68,10 +68,10 @@ def model_training_lstm():
|
|
dh.opt.features = list(feas)
|
|
dh.opt.features = list(feas)
|
|
train_x, train_y, valid_x, valid_y, scaled_train_bytes, scaled_target_bytes, scaled_cap = dh.train_data_handler(train_data, time_series=args['time_series'])
|
|
train_x, train_y, valid_x, valid_y, scaled_train_bytes, scaled_target_bytes, scaled_cap = dh.train_data_handler(train_data, time_series=args['time_series'])
|
|
else:
|
|
else:
|
|
- model = trans.get_transformer_model(trans.opt, time_series=args['time_series'], lstm_type=1)
|
|
|
|
|
|
+ model = trans.get_transformer_model(trans.opt, time_series=args['time_series'])
|
|
logger.info("训练数据特征,不满足,加强训练模型特征")
|
|
logger.info("训练数据特征,不满足,加强训练模型特征")
|
|
else:
|
|
else:
|
|
- model = trans.get_transformer_model(trans.opt, time_series=args['time_series'], lstm_type=1)
|
|
|
|
|
|
+ model = trans.get_transformer_model(trans.opt, time_series=args['time_series'])
|
|
ts_model = trans.training(model, [train_x, train_y, valid_x, valid_y])
|
|
ts_model = trans.training(model, [train_x, train_y, valid_x, valid_y])
|
|
args['Model']['features'] = ','.join(dh.opt.features)
|
|
args['Model']['features'] = ','.join(dh.opt.features)
|
|
args['params'] = json.dumps(args)
|
|
args['params'] = json.dumps(args)
|
|
@@ -97,7 +97,7 @@ def model_training_lstm():
|
|
if __name__ == "__main__":
|
|
if __name__ == "__main__":
|
|
print("Program starts execution!")
|
|
print("Program starts execution!")
|
|
from waitress import serve
|
|
from waitress import serve
|
|
- serve(app, host="0.0.0.0", port=10115,
|
|
|
|
|
|
+ serve(app, host="0.0.0.0", port=10131,
|
|
threads=8, # 指定线程数(默认4,根据硬件调整)
|
|
threads=8, # 指定线程数(默认4,根据硬件调整)
|
|
channel_timeout=600 # 连接超时时间(秒)
|
|
channel_timeout=600 # 连接超时时间(秒)
|
|
)
|
|
)
|