1. 程式人生 > >深度學習Keras框架筆記之TimeDistributedDense類

深度學習Keras框架筆記之TimeDistributedDense類

nts ini OS sample con stream 輸出 without 實例

深度學習Keras框架筆記之TimeDistributedDense類使用方法筆記

例:

keras.layers.core.TimeDistributedDense(output_dim,init=‘glorot_uniform‘, activation=‘linear‘, weights=None  
W_regularizer=None, b_regularizer=None, activity_regularizer=None, W_constraint=None, b_constraint=None,  
input_dim=None, input_length=None)   

這是一個基於時間維度的全連接層。主要就是用來構建RNN(遞歸神經網絡)的,但是在構建RNN時需要設置return_sequences=True。

inputshape: 3維 tensor(nb_samples, timesteps,input_dim)

參數:

  • output_dim: int >= 0,輸出結果的維度
  • init : 初始化權值的函數名稱或Theano function。可以使用Keras內置的,也可以傳遞自己編寫的Theano function。如果不給weights傳遞參數時,則該參數必須指明。
  • activation : 激活函數名稱或者Theano function。可以使用Keras內置的,也可以是傳遞自己編寫的Theano function。如果不明確指定,那麽將沒有激活函數會被應用。
  • weights :用於初始化權值的numpy arrays組成的list。這個List至少有1個元素,其shape為(input_dim, output_dim)。(如果指定init了,那麽weights可以賦值None)
  • W_regularizer:權值的規則化項,必須傳入一個WeightRegularizer的實例(比如L1或L2規則化項)。
  • b_regularizer:偏置值的規則化項,必須傳入一個WeightRegularizer的實例(比如L1或L2規則化項)。
  • activity_regularizer:網絡輸出的規則化項,必須傳入一個ActivityRegularizer的實例。
  • W_constraint:權值約束,必須傳入一個constraints的實例。
  • b_constraint:偏置約束,必須傳入一個constraints的實例。
  • input_dim:輸入數據的維度。這個參數會在模型的第一層中用到。
  • input_length:Length of input sequences, whenit is constant. This argument is required if you are going to connect Flattenthen Dense layers upstream (without it, the shape of the dense outputs cannotbe computed).
  • 例如:
  • # input shape: (nb_samples, timesteps,10)  
    model.add(LSTM(5, return_sequences=True, input_dim=10)) # output shape: (nb_samples, timesteps, 5)  
    model.add(TimeDistributedDense(15)) # output shape:(nb_samples, timesteps, 15)  
    

      

深度學習Keras框架筆記之TimeDistributedDense類