1+ from infer_pack .models_onnx import SynthesizerTrnMs256NSFsid
2+ import torch
3+
4+ person = "Shiroha/shiroha.pth"
5+ exported_path = "model.onnx"
6+
7+
8+
9+ cpt = torch .load (person , map_location = "cpu" )
10+ cpt ["config" ][- 3 ]= cpt ["weight" ]["emb_g.weight" ].shape [0 ]#n_spk
11+ print (* cpt ["config" ])
12+ net_g = SynthesizerTrnMs256NSFsid (* cpt ["config" ], is_half = False )
13+ net_g .load_state_dict (cpt ["weight" ], strict = False )
14+
15+ test_phone = torch .rand (1 , 200 , 256 )
16+ test_phone_lengths = torch .tensor ([200 ]).long ()
17+ test_pitch = torch .randint (size = (1 ,200 ),low = 5 ,high = 255 )
18+ test_pitchf = torch .rand (1 , 200 )
19+ test_ds = torch .LongTensor ([0 ])
20+ test_rnd = torch .rand (1 , 192 , 200 )
21+ input_names = ["phone" , "phone_lengths" , "pitch" , "pitchf" , "ds" , "rnd" ]
22+ output_names = ["audio" , ]
23+ device = "cpu"
24+ torch .onnx .export (net_g ,
25+ (
26+ test_phone .to (device ),
27+ test_phone_lengths .to (device ),
28+ test_pitch .to (device ),
29+ test_pitchf .to (device ),
30+ test_ds .to (device ),
31+ test_rnd .to (device )
32+ ),
33+ exported_path ,
34+ dynamic_axes = {
35+ "phone" : [1 ],
36+ "pitch" : [1 ],
37+ "pitchf" : [1 ],
38+ "rnd" : [2 ],
39+ },
40+ do_constant_folding = False ,
41+ opset_version = 16 ,
42+ verbose = False ,
43+ input_names = input_names ,
44+ output_names = output_names )
0 commit comments