當前位置: 首頁>>代碼示例>>Python>>正文


Python layers.RNN屬性代碼示例

本文整理匯總了Python中keras.layers.RNN屬性的典型用法代碼示例。如果您正苦於以下問題:Python layers.RNN屬性的具體用法?Python layers.RNN怎麽用?Python layers.RNN使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在keras.layers的用法示例。


在下文中一共展示了layers.RNN屬性的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from keras import layers [as 別名]
# 或者: from keras.layers import RNN [as 別名]
def __init__(self, layers, cell_type, cell_params):
        """
        Build the rnn with the given number of layers.
        :param layers: list
            list of integers. The i-th element of the list is the number of hidden neurons for the i-th layer.
        :param cell_type: 'gru', 'rnn', 'lstm'
        :param cell_params: dict
            A dictionary containing all the paramters for the RNN cell.
            see keras.layers.LSTMCell, keras.layers.GRUCell or keras.layers.SimpleRNNCell for more details.
        """
        # init params
        self.model = None
        self.horizon = None
        self.layers = layers
        self.cell_params = cell_params
        if cell_type == 'lstm':
            self.cell = LSTMCell
        elif cell_type == 'gru':
            self.cell = GRUCell
        elif cell_type == 'rnn':
            self.cell = SimpleRNNCell
        else:
            raise NotImplementedError('{0} is not a valid cell type.'.format(cell_type))
        # Build deep rnn
        self.rnn = self._build_rnn() 
開發者ID:albertogaspar,項目名稱:dts,代碼行數:27,代碼來源:Recurrent.py

示例2: _build_rnn

# 需要導入模塊: from keras import layers [as 別名]
# 或者: from keras.layers import RNN [as 別名]
def _build_rnn(self):
        cells = []
        for _ in range(self.layers):
            cells.append(self.cell(**self.cell_params))
        deep_rnn = RNN(cells, return_sequences=False, return_state=False)
        return deep_rnn 
開發者ID:albertogaspar,項目名稱:dts,代碼行數:8,代碼來源:Recurrent.py

示例3: __init__

# 需要導入模塊: from keras import layers [as 別名]
# 或者: from keras.layers import RNN [as 別名]
def __init__(self,
                 encoder_layers,
                 decoder_layers,
                 output_sequence_length,
                 dropout=0.0,
                 l2=0.01,
                 cell_type='lstm'):
        """
        :param encoder_layers: list
            encoder (RNN) architecture: [n_hidden_units_1st_layer, n_hidden_units_2nd_layer, ...]
        :param decoder_layers: list
            decoder (RNN) architecture: [n_hidden_units_1st_layer, n_hidden_units_2nd_layer, ...]
        :param output_sequence_length: int
            number of timestep to be predicted.
        :param cell_type: str
            gru or lstm.
        """
        self.encoder_layers = encoder_layers
        self.decoder_layers = decoder_layers
        self.output_sequence_length = output_sequence_length
        self.dropout = dropout
        self.l2 = l2
        if cell_type == 'lstm':
            self.cell = LSTMCell
        elif cell_type == 'gru':
            self.cell = GRUCell
        else:
            raise ValueError('{0} is not a valid cell type. Choose between gru and lstm.'.format(cell_type)) 
開發者ID:albertogaspar,項目名稱:dts,代碼行數:30,代碼來源:Seq2Seq.py

示例4: _build_encoder

# 需要導入模塊: from keras import layers [as 別名]
# 或者: from keras.layers import RNN [as 別名]
def _build_encoder(self):
        """
        Build the encoder multilayer RNN (stacked RNN)
        """
        # Create a list of RNN Cells, these get stacked one after the other in the RNN,
        # implementing an efficient stacked RNN
        encoder_cells = []
        for n_hidden_neurons in self.encoder_layers:
            encoder_cells.append(self.cell(units=n_hidden_neurons,
                                           dropout=self.dropout,
                                           kernel_regularizer=l2(self.l2),
                                           recurrent_regularizer=l2(self.l2)))

        self.encoder = RNN(encoder_cells, return_state=True, name='encoder') 
開發者ID:albertogaspar,項目名稱:dts,代碼行數:16,代碼來源:Seq2Seq.py

示例5: _build_decoder

# 需要導入模塊: from keras import layers [as 別名]
# 或者: from keras.layers import RNN [as 別名]
def _build_decoder(self):
        decoder_cells = []
        for n_hidden_neurons in self.decoder_layers:
            decoder_cells.append(self.cell(units=n_hidden_neurons,
                                           dropout=self.dropout,
                                           kernel_regularizer=l2(self.l2),
                                           recurrent_regularizer=l2(self.l2)
                                           ))
        # return output for EACH timestamp
        self.decoder = RNN(decoder_cells, return_sequences=True, return_state=True, name='decoder') 
開發者ID:albertogaspar,項目名稱:dts,代碼行數:12,代碼來源:Seq2Seq.py


注:本文中的keras.layers.RNN屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。