The article is with respect to LSTM model apply
Introduction
As our company’s project requires the use of LSTM models for frame-to-frame movement classification. So this article is about how to use LSTM models.
一、Picture comprehension process
二、Code Usage
'''
input_size shape is (batchsize,sequence_length,features).hidden_size is h(t) eigenvector, the larger this hidden_size parameter is, the more features the next sequence outputs, the more computationally intensive it is, but it may alse be overfitted. batchfirst is true,input_size is (batchsize,sequence_length,features),but if batchfirst is False, input_size shape is (sequence_length, batch_size,input_size).
bidirectional is true, this is because LSTM become Bidirectional LSTM, This is become better.
'''
self.lstm = nn.LSTM(input_size, hidden_size, num_layers, batch_first=True, bidirectional=True)
'''
LSTM层数*双向,批次大小,隐藏层维度
'''
h0 = torch.zeros(self.lstm.num_layers * 2, b, self.lstm.hidden_size).to(x.device)
c0 = torch.zeros(self.lstm.num_layers * 2, b, self.lstm.hidden_size).to(x.device)
out, _ = self.lstm(x, (h0, c0))
总结
会用就行