The subnetwork that is used in TFN for video and audio in the pre-fusion stage
| 7 | |
| 8 | ## 这两个模块都是用在 TFN 中的 (video|audio) |
| 9 | class MLPEncoder(nn.Module): |
| 10 | ''' |
| 11 | The subnetwork that is used in TFN for video and audio in the pre-fusion stage |
| 12 | ''' |
| 13 | |
| 14 | def __init__(self, in_size, hidden_size, dropout): |
| 15 | ''' |
| 16 | Args: |
| 17 | in_size: input dimension |
| 18 | hidden_size: hidden layer dimension |
| 19 | dropout: dropout probability |
| 20 | Output: |
| 21 | (return value in forward) a tensor of shape (batch_size, hidden_size) |
| 22 | ''' |
| 23 | super(MLPEncoder, self).__init__() |
| 24 | # self.norm = nn.BatchNorm1d(in_size) |
| 25 | self.drop = nn.Dropout(p=dropout) |
| 26 | self.linear_1 = nn.Linear(in_size, hidden_size) |
| 27 | self.linear_2 = nn.Linear(hidden_size, hidden_size) |
| 28 | self.linear_3 = nn.Linear(hidden_size, hidden_size) |
| 29 | |
| 30 | def forward(self, x): |
| 31 | ''' |
| 32 | Args: |
| 33 | x: tensor of shape (batch_size, in_size) |
| 34 | ''' |
| 35 | # normed = self.norm(x) |
| 36 | dropped = self.drop(x) |
| 37 | y_1 = F.relu(self.linear_1(dropped)) |
| 38 | y_2 = F.relu(self.linear_2(y_1)) |
| 39 | y_3 = F.relu(self.linear_3(y_2)) |
| 40 | |
| 41 | return y_3 |
| 42 | |
| 43 | |
| 44 | # TFN 中的文本编码,额外需要lstm 操作 [感觉是audio|video] |