微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何转换 torchscript 模型以在 OpenCV 中使用它?

如何解决如何转换 torchscript 模型以在 OpenCV 中使用它?

我在 torchscript 'model.pt' 中得到了模型,我想在 OpenCV 中加载它,这可能吗? 我在谷歌找到了一些东西,但没有用;/你有什么东西可以将 torscript 模型导出到 opencv 'onnx' 吗?

import torch

path = "model.pt"

model = torch.jit.load('model.pt')
Convert_ONNX()

def Convert_ONNX():

    # set the model to inference mode
    model.eval()

    # Let's create a dummy input tensor
    dummy_input = torch.randn(1,3,32,requires_grad=True)

    # Export the model
    torch.onnx.export(model,# model being run
         dummy_input,# model input (or a tuple for multiple inputs)
         "ImageClassifier.onnx",# where to save the model
         export_params=True,# store the trained parameter weights inside the model file
         opset_version=10,# the ONNX version to export the model to
         do_constant_folding=True,# whether to execute constant folding for optimization
         input_names = ['modelInput'],# the model's input names
         output_names = ['modelOutput'],# the model's output names
         dynamic_axes={'modelInput' : {0 : 'batch_size'},# variable length axes
                                'modelOutput' : {0 : 'batch_size'}})
    print(" ")
    print('Model has been converted to ONNX')

代码给我错误

RuntimeError:
UnkNown builtin op: torchvision::nms.
Could not find any similar ops to torchvision::nms. This op may not exist or may not be currently supported in TorchScript.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。