Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Create custom classifier
- class PoolingLinearClassifierSoftmax(nn.Module):
- def __init__(self, layers, drops):
- super().__init__()
- self.layers = nn.ModuleList([
- LinearBlock(layers[i], layers[i + 1], drops[i]) for i in range(len(layers) - 1)])
- def pool(self, x, bs, is_max):
- f = F.adaptive_max_pool1d if is_max else F.adaptive_avg_pool1d
- return f(x.permute(1,2,0), (1,)).view(bs,-1)
- def forward(self, input):
- raw_outputs, outputs = input
- output = outputs[-1]
- sl,bs,_ = output.size()
- avgpool = self.pool(output, bs, False)
- mxpool = self.pool(output, bs, True)
- x = torch.cat([output[-1], mxpool, avgpool], 1)
- for l in self.layers:
- l_x = l(x)
- x = F.relu(l_x)
- l_x = F.softmax(l_x)
- return l_x, raw_outputs, outputs
Add Comment
Please, Sign In to add comment