def make_default_model(self): self.model.add( KERAS_LSTM(128, input_shape=(self.input_shape[0], self.input_shape[1]))) self.model.add(Dropout(0.5)) self.model.add(Dense(32, activation='relu')) self.model.add(Dense(16, activation='tanh'))
def make(cls, input_shape: int, rnn_size: int, hidden_size: int, dropout: float = 0.5, n_classes: int = 6, lr: float = 0.001): """ 搭建模型 Args: input_shape (int): 特征维度 rnn_size (int): LSTM 隐藏层大小 hidden_size (int): 全连接层大小 dropout (float, optional, default=0.5): dropout n_classes (int, optional, default=6): 标签种类数量 lr (float, optional, default=0.001): 学习率 """ model = Sequential() model.add(KERAS_LSTM( rnn_size, input_shape=(1, input_shape))) # (time_steps = 1, n_feats) model.add(Dropout(dropout)) model.add(Dense(hidden_size, activation='relu')) # model.add(Dense(rnn_size, activation='tanh')) model.add(Dense(n_classes, activation='softmax')) # 分类层 optimzer = Adam(lr=lr) model.compile(loss='categorical_crossentropy', optimizer=optimzer, metrics=['accuracy']) return cls(model)
def make_default_model(self): """ Makes the LSTM model with keras with the default hyper parameters. """ self.model.add( KERAS_LSTM(128, input_shape=(self.input_shape[0], self.input_shape[1]))) self.model.add(Dropout(0.5)) self.model.add(Dense(32, activation='relu')) self.model.add(Dense(16, activation='tanh'))
def make_model(self): self.model.add(KERAS_LSTM(128, input_shape=(1, self.input_shape))) self.model.add(Dropout(0.5)) self.model.add(Dense(32, activation='relu'))
def make_model(self, rnn_size, hidden_size, dropout=0.5, **params): self.model.add(KERAS_LSTM( rnn_size, input_shape=(1, self.input_shape))) # (time_steps = 1, n_feats) self.model.add(Dropout(dropout)) self.model.add(Dense(hidden_size, activation='relu'))