Conversion scripts
Browse files- convert/core.py +26 -0
convert/core.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""SCNet without its STFT/iSTFT: spec [1,4,2049,T] -> stems [1,16,2049,T]. Same maths as SCNet.forward."""
|
| 2 |
+
from collections import deque
|
| 3 |
+
import torch
|
| 4 |
+
from torch import nn
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class SCNetCore(nn.Module):
|
| 8 |
+
def __init__(self, m):
|
| 9 |
+
super().__init__()
|
| 10 |
+
self.m = m
|
| 11 |
+
|
| 12 |
+
def forward(self, x):
|
| 13 |
+
m = self.m
|
| 14 |
+
B, C, Fr, T = x.shape
|
| 15 |
+
mean = x.mean(dim=(1, 2, 3), keepdim=True)
|
| 16 |
+
std = x.std(dim=(1, 2, 3), keepdim=True)
|
| 17 |
+
x = (x - mean) / (1e-5 + std)
|
| 18 |
+
skips, lens, olens = deque(), deque(), deque()
|
| 19 |
+
for sd in m.encoder:
|
| 20 |
+
x, skip, l, ol = sd(x)
|
| 21 |
+
skips.append(skip); lens.append(l); olens.append(ol)
|
| 22 |
+
x = m.separation_net(x)
|
| 23 |
+
for fusion, su in m.decoder:
|
| 24 |
+
x = fusion(x, skips.pop())
|
| 25 |
+
x = su(x, lens.pop(), olens.pop())
|
| 26 |
+
return x * std + mean
|