Spaces:
Sleeping
Sleeping
File size: 653 Bytes
2fd6166 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
import torch.nn as nn
import torch
__all__ = ['SE3d']
class Swish(nn.Module):
def forward(self,x):
return x * torch.sigmoid(x)
class SE3d(nn.Module):
def __init__(self, channel, reduction=8, use_relu=False):
super().__init__()
self.fc = nn.Sequential(
nn.Linear(channel, channel // reduction, bias=False),
nn.ReLU(True) if use_relu else Swish() ,
nn.Linear(channel // reduction, channel, bias=False),
nn.Sigmoid()
)
def forward(self, inputs):
return inputs * self.fc(inputs.mean(-1).mean(-1).mean(-1)).view(inputs.shape[0], inputs.shape[1], 1, 1, 1)
|