Spaces:
Runtime error
Runtime error
Update src/sbv2/synthesizer_trn.py
Browse files- src/sbv2/synthesizer_trn.py +70 -109
src/sbv2/synthesizer_trn.py
CHANGED
@@ -1,109 +1,70 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
self.
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
self.
|
71 |
-
self.out_channels = out_channels
|
72 |
-
self.dec_kernel_size = dec_kernel_size
|
73 |
-
self.enc_channels = enc_channels
|
74 |
-
self.enc_out_channels = enc_out_channels
|
75 |
-
self.enc_kernel_size = enc_kernel_size
|
76 |
-
self.enc_dilation_rate = enc_dilation_rate
|
77 |
-
self.enc_n_layers = enc_n_layers
|
78 |
-
self.flow_hidden_channels = flow_hidden_channels
|
79 |
-
self.flow_kernel_size = flow_kernel_size
|
80 |
-
self.flow_n_layers = flow_n_layers
|
81 |
-
self.flow_n_flows = flow_n_flows
|
82 |
-
self.sdp_hidden_channels = sdp_hidden_channels
|
83 |
-
self.sdp_kernel_size = sdp_kernel_size
|
84 |
-
self.sdp_n_layers = sdp_n_layers
|
85 |
-
self.sdp_dropout = sdp_dropout
|
86 |
-
self.sampling_rate = sampling_rate
|
87 |
-
self.filter_length = filter_length
|
88 |
-
self.hop_length = hop_length
|
89 |
-
self.win_length = win_length
|
90 |
-
|
91 |
-
# ネットワークモジュール
|
92 |
-
self.enc_p = PosteriorEncoder(
|
93 |
-
spec_channels, inter_channels, hidden_channels,
|
94 |
-
kernel_size, enc_dilation_rate, int(enc_n_layers))
|
95 |
-
self.decoder = Generator(
|
96 |
-
upsample_rates, upsample_initial_channel)
|
97 |
-
self.flow = ResidualCouplingBlock(
|
98 |
-
inter_channels, flow_hidden_channels, flow_kernel_size, flow_n_layers)
|
99 |
-
self.flow_post = Flip()
|
100 |
-
self.dp = DurationPredictor(
|
101 |
-
inter_channels, filter_channels, kernel_size, p_dropout)
|
102 |
-
self.sdp = StochasticDurationPredictor(
|
103 |
-
inter_channels, filter_channels, kernel_size, p_dropout)
|
104 |
-
|
105 |
-
def forward(self, *args, **kwargs):
|
106 |
-
raise NotImplementedError("Training用 forwardは未実装です")
|
107 |
-
|
108 |
-
def infer(self, *args, **kwargs):
|
109 |
-
raise NotImplementedError("推論用 inferは未実装です")
|
|
|
1 |
+
import torch.nn as nn
|
2 |
+
from src.sbv2.generator import Generator
|
3 |
+
from src.sbv2.posterior_encoder import PosteriorEncoder
|
4 |
+
|
5 |
+
class SynthesizerTrn(nn.Module):
|
6 |
+
def __init__(
|
7 |
+
self,
|
8 |
+
n_vocab,
|
9 |
+
p_dropout,
|
10 |
+
segment_size,
|
11 |
+
inter_channels,
|
12 |
+
out_channels,
|
13 |
+
hidden_channels,
|
14 |
+
filter_channels,
|
15 |
+
dec_kernel_size,
|
16 |
+
enc_channels,
|
17 |
+
enc_out_channels,
|
18 |
+
enc_kernel_size,
|
19 |
+
enc_dilation_rate,
|
20 |
+
enc_n_layers,
|
21 |
+
flow_hidden_channels,
|
22 |
+
flow_kernel_size,
|
23 |
+
flow_n_layers,
|
24 |
+
flow_n_flows,
|
25 |
+
sdp_hidden_channels,
|
26 |
+
sdp_kernel_size,
|
27 |
+
sdp_n_layers,
|
28 |
+
sdp_dropout,
|
29 |
+
sampling_rate,
|
30 |
+
filter_length,
|
31 |
+
hop_length,
|
32 |
+
win_length,
|
33 |
+
resblock,
|
34 |
+
resblock_kernel_sizes,
|
35 |
+
resblock_dilation_sizes,
|
36 |
+
upsample_rates,
|
37 |
+
upsample_initial_channel,
|
38 |
+
upsample_kernel_sizes,
|
39 |
+
gin_channels
|
40 |
+
):
|
41 |
+
super().__init__()
|
42 |
+
|
43 |
+
# PosteriorEncoder
|
44 |
+
self.enc_p = PosteriorEncoder(
|
45 |
+
in_channels=enc_channels,
|
46 |
+
out_channels=enc_out_channels,
|
47 |
+
hidden_channels=hidden_channels,
|
48 |
+
kernel_size=enc_kernel_size,
|
49 |
+
dilation_rate=enc_dilation_rate,
|
50 |
+
n_layers=enc_n_layers
|
51 |
+
)
|
52 |
+
|
53 |
+
# Generator (Decoder)
|
54 |
+
self.decoder = Generator(
|
55 |
+
upsample_rates=upsample_rates,
|
56 |
+
upsample_initial_channel=upsample_initial_channel,
|
57 |
+
resblock_kernel_sizes=resblock_kernel_sizes,
|
58 |
+
resblock_dilation_sizes=resblock_dilation_sizes,
|
59 |
+
resblock=resblock,
|
60 |
+
upsample_kernel_sizes=upsample_kernel_sizes,
|
61 |
+
inter_channels=inter_channels,
|
62 |
+
out_channels=out_channels,
|
63 |
+
sampling_rate=sampling_rate
|
64 |
+
)
|
65 |
+
|
66 |
+
# その他層(ここでは省略)
|
67 |
+
|
68 |
+
def infer(self, x, noise_scale=0.667, noise_scale_w=0.8, length_scale=1.0):
|
69 |
+
# 仮の推論実装(必要に応じて調整)
|
70 |
+
return self.decoder(x), None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|