| 15 | |
| 16 | |
| 17 | class TextCNN(nn.Module): |
| 18 | def __init__(self, fea_dim, vocab_size): |
| 19 | super(TextCNN, self).__init__() |
| 20 | self.vocab_size = vocab_size |
| 21 | self.fea_dim=fea_dim |
| 22 | |
| 23 | self.channel_in = 1 |
| 24 | self.filter_num = 14 |
| 25 | self.window_size = [3,4,5] |
| 26 | |
| 27 | self.textcnn =nn.ModuleList([nn.Conv2d(self.channel_in, self.filter_num, (K,self.vocab_size)) for K in self.window_size]) |
| 28 | self.linear = nn.Sequential(torch.nn.Linear(len(self.window_size) * self.filter_num, self.fea_dim),torch.nn.ReLU()) |
| 29 | |
| 30 | def forward(self, inputs): |
| 31 | text = inputs.unsqueeze(1) |
| 32 | text = [F.relu(conv(text)).squeeze(3) for conv in self.textcnn] |
| 33 | text = [F.max_pool1d(i.squeeze(2), i.shape[-1]).squeeze(2) for i in text] |
| 34 | fea_text = torch.cat(text, 1) |
| 35 | fea_text = self.linear(fea_text) |
| 36 | |
| 37 | return fea_text |
| 38 | |
| 39 | |
| 40 | class VideoEncoder(nn.Module): |