forked from huawei/openGauss-server
Merge pull request '新增了对文件的部分注释' (#10) from xinran/openGauss-server:master into master
This commit is contained in:
commit
8e9089b6fe
|
|
@ -539,13 +539,14 @@ class RnnModel():
|
||||||
keras.backend.clear_session()
|
keras.backend.clear_session()
|
||||||
set_session(self.session)
|
set_session(self.session)
|
||||||
with self.graph.as_default():
|
with self.graph.as_default():
|
||||||
|
# Judge whether the model needs to be initialized according to the changes of the model input and output dimensions.
|
||||||
feature, label, need_init = self.parse(filename)
|
feature, label, need_init = self.parse(filename)
|
||||||
os.environ['CUDA_VISIBLE_DEVICES'] = '0'
|
os.environ['CUDA_VISIBLE_DEVICES'] = '0'
|
||||||
epsilon = self.model_info.make_epsilon()
|
epsilon = self.model_info.make_epsilon()
|
||||||
if need_init:
|
if need_init:# Cold start training
|
||||||
epoch_start = 0
|
epoch_start = 0
|
||||||
self.model = self._build_model(epsilon)
|
self.model = self._build_model(epsilon)
|
||||||
else:
|
else:# Incremental training
|
||||||
epoch_start = int(self.model_info.last_epoch)
|
epoch_start = int(self.model_info.last_epoch)
|
||||||
ratio_error = ratio_error_loss_wrapper(epsilon)
|
ratio_error = ratio_error_loss_wrapper(epsilon)
|
||||||
ratio_acc_2 = ratio_error_acc_wrapper(epsilon, 2)
|
ratio_acc_2 = ratio_error_acc_wrapper(epsilon, 2)
|
||||||
|
|
@ -556,12 +557,16 @@ class RnnModel():
|
||||||
log_path = os.path.realpath(os.path.join(settings.PATH_LOG, self.model_info.model_name + '_log.json'))
|
log_path = os.path.realpath(os.path.join(settings.PATH_LOG, self.model_info.model_name + '_log.json'))
|
||||||
if not os.path.exists(log_path):
|
if not os.path.exists(log_path):
|
||||||
os.mknod(log_path, mode=0o600)
|
os.mknod(log_path, mode=0o600)
|
||||||
|
# Training logging callback function
|
||||||
json_logging_callback = LossHistory(log_path, self.model_info.model_name, self.model_info.last_epoch)
|
json_logging_callback = LossHistory(log_path, self.model_info.model_name, self.model_info.last_epoch)
|
||||||
|
# Data segmentation
|
||||||
X_train, X_val, y_train, y_val = \
|
X_train, X_val, y_train, y_val = \
|
||||||
train_test_split(feature, label, test_size=0.1)
|
train_test_split(feature, label, test_size=0.1)
|
||||||
|
# model training
|
||||||
self.model.fit(X_train, y_train, epochs=self.model_info.last_epoch,
|
self.model.fit(X_train, y_train, epochs=self.model_info.last_epoch,
|
||||||
batch_size=int(self.model_info.batch_size), validation_data=(X_val, y_val),
|
batch_size=int(self.model_info.batch_size), validation_data=(X_val, y_val),
|
||||||
verbose=0, initial_epoch=epoch_start, callbacks=[json_logging_callback])
|
verbose=0, initial_epoch=epoch_start, callbacks=[json_logging_callback])
|
||||||
|
# save model
|
||||||
self.model.save(self.model_info.model_path)
|
self.model.save(self.model_info.model_path)
|
||||||
val_pred = self.model.predict(X_val)
|
val_pred = self.model.predict(X_val)
|
||||||
val_re = get_ratio_errors_general(val_pred, y_val, epsilon)
|
val_re = get_ratio_errors_general(val_pred, y_val, epsilon)
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ from . import AbstractModel
|
||||||
|
|
||||||
|
|
||||||
class TemplateModel(AbstractModel):
|
class TemplateModel(AbstractModel):
|
||||||
|
# Initialize algorithm parameters
|
||||||
def __init__(self, params):
|
def __init__(self, params):
|
||||||
super().__init__(params)
|
super().__init__(params)
|
||||||
self.bias = 1e-5
|
self.bias = 1e-5
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue