Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to convert to core model #23

Open
zhouyijian opened this issue Feb 14, 2023 · 0 comments
Open

how to convert to core model #23

zhouyijian opened this issue Feb 14, 2023 · 0 comments

Comments

@zhouyijian
Copy link

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant