PaddlePaddle / PaddleSpeech

Easy-to-use Speech Toolkit including Self-Supervised Learning model, SOTA/Streaming ASR with punctuation, Streaming TTS with text frontend, Speaker Verification System, End-to-End Speech Translation and Keyword Spotting. Won NAACL2022 Best Demo Award.
https://paddlespeech.readthedocs.io
Apache License 2.0
10.96k stars 1.83k forks source link

将vits-csmsc导出onnx出现错误 #3378

Open Xwmiss opened 1 year ago

Xwmiss commented 1 year ago

General Question

在导出vits-csmsc的onnx模型时出现问题,使用的代码如下

import argparse from pathlib import Path

import paddle import soundfile as sf import yaml from timer import timer from yacs.config import CfgNode from paddle.static import InputSpec import os

from paddle import jit from paddlespeech.t2s.models.vits import VITS from paddlespeech.t2s.models.vits import VITSInference from paddlespeech.t2s.utils import str2bool

paddle.set_device("cpu")

config = "/home/cw/code/tts/PaddleSpeech/checkpoint/vits_csmsc_ckpt_1.4.0/default.yaml" ckpt = "/home/cw/code/tts/PaddleSpeech/checkpoint/vits_csmsc_ckpt_1.4.0/snapshot_iter_150000.pdz" phones_dict = ( "/home/cw/code/tts/PaddleSpeech/checkpoint/vits_csmsc_ckpt_1.4.0/phone_id_map.txt" )

with open(config) as f: config = CfgNode(yaml.safe_load(f))

with open(phones_dict, "r") as f:
    phn_id = [line.strip().split() for line in f.readlines()]
vocab_size = len(phn_id)
print("vocab_size:", vocab_size)

odim = config.n_fft // 2 + 1
config["model"]["generator_params"]["spks"] = None

vits = VITS(idim=vocab_size, odim=odim, **config["model"])
vits.set_state_dict(paddle.load(ckpt)["main_params"])
vits.eval()

vits_inference = VITSInference(vits)

# transfer dygraph to static
vits_inference = jit.to_static(
    vits_inference, input_spec=[InputSpec([50], dtype=paddle.int64)]
)

save_path = "/home/cw/code/tts/PaddleSpeech/rknn_test/test.onnx" # 需要保存的路径 x_spec = paddle.static.InputSpec( [50], "int64", "phone_ids" ) # 为模型指定输入的形状和数据类型,支持持 Tensor 或 InputSpec ,InputSpec 支持动态的 shape。 paddle.onnx.export(vits_inference, save_path, input_spec=[x_spec], opset_version=12)`

报错结果如下: image

Xwmiss commented 1 year ago

应该是paddle在动转静的时候,输入出现了问题?

Xwmiss commented 1 year ago

https://github.com/PaddlePaddle/PaddleSpeech/issues/2826 @yt605155624 看到了此前的问题,看来paddle上面的vits还是不支持导出onnx。 但是奇怪的在于,哪怕是最后转成onnx不能成功,但是当我使用动转静的时候,也是出现上面一样的错误。。。

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.