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