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

Convert to onnx #91

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions main_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from options.opts import get_conversion_arguments
from utils import logger
from utils.checkpoint_utils import CHECKPOINT_EXTN
from utils.pytorch_to_coreml import convert_pytorch_to_coreml
from utils.pytorch_to_coreml import convert_pytorch_to_coreml, create_rand_tensor


def main_worker_conversion(args: Optional[List[str]] = None):
Expand Down Expand Up @@ -45,14 +45,17 @@ def main_worker_conversion(args: Optional[List[str]] = None):

conversion_success = False
try:
converted_models_dict = convert_pytorch_to_coreml(
opts=opts, pytorch_model=model
)
converted_models_dict = convert_pytorch_to_coreml(opts=opts, pytorch_model=model)
coreml_model = converted_models_dict["coreml"]
jit_model = converted_models_dict["jit"]
jit_optimized = converted_models_dict["jit_optimized"]

coreml_model.save(model_dst_loc)
torch.onnx.export(
model,
create_rand_tensor(opts=opts, device="cpu"),
model_dst_loc.replace(f".{coreml_extn}", ".onnx"),
)

torch.jit.save(
jit_model,
Expand All @@ -67,9 +70,7 @@ def main_worker_conversion(args: Optional[List[str]] = None):
conversion_success = True
except Exception as e:
logger.error(
"PyTorch to CoreML conversion failed. See below for error details:\n {}".format(
e
)
"PyTorch to CoreML conversion failed. See below for error details:\n {}".format(e)
)

if conversion_success:
Expand Down