将torchscript模型转换为Core ML

2024-10-05 10:14:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试将Detectron 2模型转换为Core ML。我已经编写了脚本,现在我有了一个“torch.jit.\u script.RecursiveScriptModule”类型的模型。如果我尝试使用以下代码将其转换为Core ML:

mlmodel = ct.converters.convert(
  torchscipt_model,
  inputs=[ct.TensorType(shape=(1, 3, 64, 64))],
)

我得到以下错误:

RuntimeError: Unknown type bool encountered in graph lowering. This type is not supported in ONNX export.

我使用以下代码编写了模型脚本(如Detectron的documentation所示)

model = build_model(cfg)
model.eval()

fields = {"pred_boxes": Boxes, "scores": torch.Tensor, "pred_classes": torch.Tensor, "pred_masks": torch.Tensor, "proposal_boxes": Boxes, "objectness_logits": torch.Tensor}

torchscipt_model = scripting_with_instances(model, fields)

你知道把我的Detectron2模型转换成Core ML的其他方法吗

非常感谢你的帮助


Tags: 代码incore模型脚本fieldsmodeltype

热门问题