| 144 | return self.w_2(self.norm(F.relu(self.w_1(x)).transpose(2, 1).contiguous()).transpose(2, 1).contiguous()) |
| 145 | |
| 146 | class Transformer(pl.LightningModule): |
| 147 | |
| 148 | def __init__(self, cfg): |
| 149 | super().__init__() |
| 150 | c = copy.deepcopy |
| 151 | attn = MultiHeadedAttention( |
| 152 | cfg.model.num_heads, |
| 153 | cfg.model.pc_feat_dim |
| 154 | ) |
| 155 | |
| 156 | ff = PositionwiseFeedForward( |
| 157 | cfg.model.pc_feat_dim, |
| 158 | cfg.model.transformer_feat_dim |
| 159 | ) |
| 160 | |
| 161 | self.model = EncoderDecoder( |
| 162 | Encoder(EncoderLayer(cfg.model.pc_feat_dim, c(attn), c(ff)), cfg.model.num_blocks), |
| 163 | Decoder(DecoderLayer(cfg.model.pc_feat_dim, c(attn), c(attn), c(ff)), cfg.model.num_blocks), |
| 164 | nn.Sequential(), |
| 165 | nn.Sequential(), |
| 166 | nn.Sequential() |
| 167 | ) |
| 168 | |
| 169 | def forward(self, src, tgt): |
| 170 | src = src.transpose(2, 1).contiguous() |
| 171 | tgt = tgt.transpose(2, 1).contiguous() |
| 172 | src_corr_feat = self.model(tgt, src, None, None).transpose(2, 1).contiguous() |
| 173 | return src_corr_feat |
no outgoing calls
no test coverage detected