forked from openvpi/DiffSinger
-
Notifications
You must be signed in to change notification settings - Fork 1
/
onnx_export_pe.py
50 lines (41 loc) · 1.12 KB
/
onnx_export_pe.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
# 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.pe.to(dev)
with torch.no_grad():
mel_input = torch.rand(1, 4097, 80).to(dev)
torch.onnx.export(
infer_ins.pe,
(
mel_input
),
"xiaoma_pe.onnx",
verbose=True,
input_names=["mel_input"],
dynamic_axes={
"mel_input": {
0: "batch_size",
1: "frames",
2: "num_mel_bin",
}
},
opset_version=11
)
print("OK")