(self, in_channel, n_head=1, norm_groups=32)
| 144 | |
| 145 | class SelfAttention(nn.Module): |
| 146 | def __init__(self, in_channel, n_head=1, norm_groups=32): |
| 147 | super().__init__() |
| 148 | |
| 149 | self.n_head = n_head |
| 150 | |
| 151 | # self.norm = nn.BatchNorm2d(in_channel) |
| 152 | self.norm = nn.GroupNorm(norm_groups, in_channel) |
| 153 | # self.norm = LayerNorm2d(in_channel) |
| 154 | self.qkv = nn.Conv2d(in_channel, in_channel * 3, 1, bias=False) |
| 155 | self.out = nn.Conv2d(in_channel, in_channel, 1) |
| 156 | |
| 157 | def forward(self, input): |
| 158 | batch, channel, height, width = input.shape |