| 94 | weight_init(self) |
| 95 | |
| 96 | class FeedForward(nn.Module): |
| 97 | def __init__(self, dim, ffn_expansion_factor, bias): |
| 98 | super(FeedForward, self).__init__() |
| 99 | hidden_features = int(dim*ffn_expansion_factor) |
| 100 | self.project_in = nn.Conv2d(dim, hidden_features*2, kernel_size=1, bias=bias) |
| 101 | self.dwconv = nn.Conv2d(hidden_features*2, hidden_features*2, kernel_size=3, stride=1, padding=1, groups=hidden_features*2, bias=bias) |
| 102 | self.project_out = nn.Conv2d(hidden_features, dim, kernel_size=1, bias=bias) |
| 103 | |
| 104 | def forward(self, x): |
| 105 | x = self.project_in(x) |
| 106 | x1, x2 = self.dwconv(x).chunk(2, dim=1) |
| 107 | x = F.gelu(x1) * x2 |
| 108 | x = self.project_out(x) |
| 109 | return x |
| 110 | |
| 111 | def initialize(self): |
| 112 | weight_init(self) |
| 113 | |
| 114 | class Attention(nn.Module): |
| 115 | def __init__(self, dim, num_heads, bias,mode): |