x: [bs,C,1,F] cache: [bs,C,T-1,F]
(self, x, cache)
| 230 | bias = bias) |
| 231 | |
| 232 | def forward(self, x, cache): |
| 233 | """ |
| 234 | x: [bs,C,1,F] |
| 235 | cache: [bs,C,T-1,F] |
| 236 | """ |
| 237 | # [bs,C,T,F] |
| 238 | inp = torch.cat([cache, x], dim = 2) |
| 239 | out_cache = inp[:, :, 1:] |
| 240 | bs, C, T, F = inp.shape |
| 241 | |
| 242 | # Upsampling operation |
| 243 | if self.F_stride > 1: |
| 244 | # [bs,C,T,F] -> [bs,C,T,F,1] -> [bs,C,T,F,F_stride] -> [bs,C,T,F_out] |
| 245 | inp = torch.cat([inp[:,:,:,:,None], torch.zeros([bs,C,T,F,self.F_stride-1])], dim = -1).reshape([bs,C,T,-1]) |
| 246 | left_pad = self.F_stride - 1 |
| 247 | if self.F_size > 1: |
| 248 | if left_pad <= self.F_size - 1: |
| 249 | inp = torch.nn.functional.pad(inp, pad = [(self.F_size - 1)*self.F_dilation-self.F_pad, (self.F_size - 1)*self.F_dilation-self.F_pad - left_pad, 0, 0]) |
| 250 | else: |
| 251 | # inp = torch.nn.functional.pad(inp, pad = [self.F_size - 1, 0, 0, 0])[:,:,:,: - (left_pad - self.F_stride + 1)] |
| 252 | raise(NotImplementedError) |
| 253 | else: |
| 254 | # inp = inp[:,:,:,:-left_pad] |
| 255 | raise(NotImplementedError) |
| 256 | |
| 257 | else: # F_stride = 1 |
| 258 | inp = torch.nn.functional.pad(inp, pad=[(self.F_size-1)*self.F_dilation-self.F_pad, (self.F_size-1)*self.F_dilation-self.F_pad]) |
| 259 | |
| 260 | outp = self.ConvTranspose2d(inp) |
| 261 | |
| 262 | return outp, out_cache |
| 263 | |
| 264 | |
| 265 | if __name__ == '__main__': |
nothing calls this directly
no outgoing calls
no test coverage detected