我微调了 BERT VITS 2 文本转语音模型,并使用 export to onnx 代码将该模型转换为 ONNX 模型。我想在 Unity 中使用 Barracuda 模型,而这只允许一个 ONNX 文件。但是,BERT VITS 2 中导出到 ONNX 代码给出了六种不同的 ONNX 模型:Speaker_dec.onnx、Speaker_dp.onnx、Speaker_emb.onnx、Speaker_enc_p.onnx、Speaker_flow.onnx、Speaker_sdp.onnx。
我尝试根据以下代码使用 ONNX API 中提供的 compose 方法合并这些模型。
import onnx
from onnx import compose
model_files = [
""
]
# Load the first model
merged_model = onnx.load(model_files[0])
# Start merging from the second model
for i in range(1, len(model_files)):
current_model = onnx.load(model_files[i])
# Add a prefix to the current model to avoid name clashes
current_model_with_prefix = compose.add_prefix(current_model, prefix=f"m{i}_")
# Now, create an io_map that connects the last output of the merged_model to the first input of current_model_with_prefix
io_map = [(output.name, input.name) for output, input in zip(merged_model.graph.output, current_model_with_prefix.graph.input)]
# Merge the models
merged_model = compose.merge_models(merged_model, current_model_with_prefix, io_map=io_map)
# Save the merged model to a new ONNX file
onnx.save(merged_model, "combined_model.onnx")
但是,当我尝试加载此模型时,遇到以下错误:
Input Name: z_in, Output Name: o
Traceback (most recent call last):
File "c:\EasyBertVits2\Playing around\testing.py", line
19, in <module>
outputs = session.run([output_name], {input_name: input_data})
File "c:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\onnxruntime\capi\onnxruntime_inference_collection.py", line 196, in run
raise ValueError("Model requires {} inputs. Input Feed contains {}".format(num_required_inputs, num_inputs))
ValueError: Model requires 2 inputs. Input Feed contains 1
如何正确合并模型,以便将其用作一个 ONNX 模型?
File "/data/user/0/com.kvassyu.coding.py/files/default.py", line 1, in <module>
from turtle import *
File "/data/user/0/com.kvassyu.coding.py/files/PYROOT3/lib/python3.8/turtle.py", line 107, in <module>
import tkinter as TK
File "/data/user/0/com.kvassyu.coding.py/files/PYROOT3/lib/python3.8/tkinter/__init__.py", line 36, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named '_tkinter'
[Process completed (code 1) - press Enter]