-
Notifications
You must be signed in to change notification settings - Fork 133
Expand file tree
/
Copy pathLSTM.h
More file actions
24 lines (20 loc) · 861 Bytes
/
Copy pathLSTM.h
File metadata and controls
24 lines (20 loc) · 861 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#ifndef LSTM_H
#define LSTM_H
#endif // LSTM_H
#include<BaseModule.h>
#include<tuple>
inline torch::nn::LSTMOptions lstmOption(int in_features, int hidden_layer_size, int num_layers, bool batch_first = false, bool bidirectional = false){
torch::nn::LSTMOptions lstmOption = torch::nn::LSTMOptions(in_features, hidden_layer_size);
lstmOption.num_layers(num_layers).batch_first(batch_first).bidirectional(bidirectional);
return lstmOption;
}
//batch_first: true for io(batch, seq, feature) else io(seq, batch, feature)
class LSTM: public torch::nn::Module{
public:
LSTM(int in_features, int hidden_layer_size, int out_size, int num_layers, bool batch_first);
torch::Tensor forward(torch::Tensor x);
private:
torch::nn::LSTM lstm{nullptr};
torch::nn::Linear ln{nullptr};
std::tuple<torch::Tensor, torch::Tensor> hidden_cell;
};