-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
作者您好 请问如何添加新的预测模型 #34
Comments
1、你这样设置使用新的模型是可以的,可能是导入的包不是你修改后的。 KERAS_MODEL = model |
很感谢您的回答 我解决了问题 发现是要把模型名称都设置成大写的 中间有些转换 导致小写的检测不到 |
此外还有一个问题问您 就是添加TCN模型的时候 好像检测不到这个模型 我使用的是keras-tcn的api 然后就报错 |
因为之前在使用TCN没有得出正确的结果,所以没有启用tcn的包。tcn不是keras内置的模型所以无法导入,需要在安装好的添包keras_predictor文件中加form keras-tcn import TCN |
是的 我就是导入 但是结果就是根本没有预测 很奇怪 不知道怎么回事 |
具体原因可能比较难找,可以先用这个简化版的试试 |
好的 谢谢您 简版上上面我是测试成功的 |
作者,您好,我在您的代码的基础上添加新模型BiGRU
def build_model(self, trainset_shape, model_name='Keras model', model_file=None):
"""
Build Keras model, eg. 'GRU', 'LSTM', 'DNN', 'BPNN', 'CUDNNLSTM', 'CUDNNGRU', model = Sequential(), or load_model.
"""
if model_file is not None and os.path.exists(str(model_file)):
print('Load Keras model:', model_file)
return load_model(model_file) # load user's saving custom model
elif isinstance(self.KERAS_MODEL, Sequential): # if not load a model
return self.KERAS_MODEL
elif self.KERAS_MODEL == 'LSTM':
model = Sequential(name=model_name)
model.add(LSTM(self.units4, input_shape=(trainset_shape[1], trainset_shape[2]), recurrent_activation='sigmoid',
activation=self.activation, return_sequences=True))
model.add(Dropout(self.dropout))
model.add(LSTM(self.units2, recurrent_activation='sigmoid', activation=self.activation, return_sequences=True))
model.add(Dropout(self.dropout))
model.add(LSTM(self.units, recurrent_activation='sigmoid', activation=self.activation, return_sequences=False))
model.add(Dropout(self.dropout))
model.add(Dense(1, activation=self.activation))
model.compile(loss=self.opt_loss, optimizer=self.opt)
return model
elif self.KERAS_MODEL == 'GRU':
model = Sequential(name=model_name)
model.add(GRU(self.units4, input_shape=(trainset_shape[1], trainset_shape[2]), recurrent_activation='sigmoid',
reset_after=True, activation=self.activation, return_sequences=True))
model.add(Dropout(self.dropout))
model.add(GRU(self.units2, recurrent_activation='sigmoid', reset_after=True, activation=self.activation, return_sequences=True))
model.add(Dropout(self.dropout))
model.add(GRU(self.units, recurrent_activation='sigmoid', reset_after=True, activation=self.activation, return_sequences=False))
model.add(Dropout(self.dropout))
model.add(Dense(1, activation=self.activation))
model.compile(loss=self.opt_loss, optimizer=self.opt)
return model
elif self.KERAS_MODEL == 'DNN':
model = Sequential(name=model_name)
model.add(Flatten(input_shape=(trainset_shape[1], trainset_shape[2])))
for _ in range(8):
model.add(Dense(self.units4, activation=self.activation))
# model.add(BatchNormalization())
model.add(Dropout(self.dropout))
model.add(Dense(self.units2, activation=self.activation))
model.add(Dropout(self.dropout))
model.add(Dense(self.units, activation=self.activation))
model.add(Dropout(self.dropout))
model.add(Dense(1, activation=self.activation))
model.compile(loss=self.opt_loss, optimizer=self.opt)
return model
elif self.KERAS_MODEL == 'BPNN':
model = Sequential(name=model_name)
model.add(Dense(self.units4, input_shape=(trainset_shape[1], trainset_shape[2]), activation=self.activation))
model.add(Dropout(self.dropout))
model.add(Flatten())
model.add(Dense(1, activation=self.activation))
model.compile(loss=self.opt_loss, optimizer=self.opt)
return model
elif self.KERAS_MODEL == 'BiGRU':
model = Sequential(name=model_name)
model.add(Bidirectional(GRU(self.units4, input_shape=(trainset_shape[1], trainset_shape[2]), recurrent_activation='sigmoid',
reset_after=True, activation=self.activation, return_sequences=True)))
model.add(Dropout(self.dropout))
model.add(Flatten())
model.add(Dense(1, activation=self.activation))
model.compile(loss=self.opt_loss, optimizer=self.opt)
return model
但是并不能被识别到 出现如下报错:
Traceback (most recent call last):
File "c:\Users\GGBond\Desktop\CAN_LSTM\main.py", line 34, in
df_result = kr.hybrid_keras_predict(data=series, show=True, plot=True, save=True)
File "c:\Users\GGBond\Desktop\CAN_LSTM\CEEMDAN_LSTM_library\keras_predictor.py", line 599, in hybrid_keras_predict
df_result = self.keras_predict(data=df, show_model=show, **kwargs) # the ensemble method with matrix input
File "c:\Users\GGBond\Desktop\CAN_LSTM\CEEMDAN_LSTM_library\keras_predictor.py", line 327, in keras_predict
else: model = self.build_model(x_train.shape, data.name, model_file)
File "c:\Users\GGBond\Desktop\CAN_LSTM\CEEMDAN_LSTM_library\keras_predictor.py", line 247, in build_model
else: raise ValueError("%s is an invalid input for KERAS_MODEL! eg. 'GRU', 'LSTM', or model = Sequential()"%self.KERAS_MODEL)
ValueError: BIGRU is an invalid input for KERAS_MODEL! eg. 'GRU', 'LSTM', or model = Sequential()
请问在代码的哪个地方能修改使之可以添加新的模型呢
The text was updated successfully, but these errors were encountered: