how to convert to core model
zhouyijian opened this issue · 0 comments
zhouyijian commented
like this?
import torch
import onnx
import coremltools as ct
构建PyTorch模型
model = ...
定义输入样本,假设输入维度为(1, 1, 44100),即单通道、采样率为44100的音频数据
input_shape = (1, 1, 44100)
input_sample = torch.randn(*input_shape)
将模型转换为ONNX模型
onnx_model_path = 'model.onnx'
torch.onnx.export(model, input_sample, onnx_model_path, input_names=['input'], output_names=['output'], opset_version=12)
将ONNX模型转换为Core ML模型
coreml_model_path = 'model.mlmodel'
coreml_model = ct.converters.onnx.convert(onnx_model_path, minimum_ios_deployment_target='13')
coreml_model.save(coreml_model_path)