-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Sign Language detection model by Google
- Loading branch information
1 parent
975b088
commit 30cb9a1
Showing
1 changed file
with
21 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import torch | ||
import torch.nn as nn | ||
|
||
# Paper: https://arxiv.org/abs/2008.04637 | ||
# Models ported from: https://github.com/google-research/google-research/tree/master/sign_language_detection | ||
|
||
class SignDetectionLSTM(nn.Module): | ||
def __init__(self, input_dim=25, input_dropout = 0.5, encoder_layers = 1, hidden_size = 2**6, encoder_bidirectional = False): | ||
super(SignDetectionLSTM, self).__init__() | ||
self.input_dropout = nn.Dropout(p=input_dropout) | ||
self.lstm = nn.LSTM(input_dim, hidden_size, encoder_layers, bidirectional=encoder_bidirectional, batch_first=True) | ||
self.linear = nn.Linear(hidden_size, 2) | ||
|
||
def forward(self, x, hidden=None): | ||
# input.shape = [batch_size, seq_length, input_dim] | ||
x = self.input_dropout(x) | ||
lstm_out, self.hidden = self.lstm(input, hidden) | ||
# shape = [batch_size, out_dim] | ||
y_pred = self.linear(self.dropout(lstm_out[:,-1,:])) | ||
return y_pred | ||
|