forked from openvpi/DiffSinger
-
Notifications
You must be signed in to change notification settings - Fork 1
/
onnx_export_hifigan.py
65 lines (52 loc) · 1.42 KB
/
onnx_export_hifigan.py
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
55
56
57
58
59
60
61
62
63
64
65
# coding=utf8
import os
import sys
import inference.svs.ds_e2e as e2e
from utils.audio import save_wav
from utils.hparams import set_hparams, hparams
import torch
root_dir = os.path.dirname(os.path.abspath(__file__))
os.environ['PYTHONPATH'] = f'"{root_dir}"'
sys.argv = [
f'{root_dir}/inference/svs/ds_e2e.py',
'--config',
f'{root_dir}/usr/configs/midi/e2e/opencpop/ds100_adj_rel.yaml',
'--exp_name',
'0228_opencpop_ds100_rel'
]
if __name__ == '__main__':
set_hparams(print_hparams=False)
dev = 'cuda'
infer_ins = e2e.DiffSingerE2EInfer(hparams)
infer_ins.vocoder.to(dev)
with torch.no_grad():
x = torch.rand(1, 80, 2).to(dev)
f0 = torch.rand(1, 2).to(dev)
x = torch.load("c.pt").to(dev)
f0 = torch.load("f0.pt").to(dev)
print(x.shape)
print(f0.shape)
torch.onnx.export(
infer_ins.vocoder,
(
x,
f0
),
"hifigan.onnx",
verbose=True,
input_names=["x", "f0"],
dynamic_axes={
"x": {
0: "batch_size",
1: "num_mel_bin",
2: "frames",
},
"f0": {
0: "batch_size",
1: "frames"
}
},
opset_version=11,
)
print(infer_ins.vocoder)
print("OK")