【问题标题】:PyTorch convert function for op 'pad' not implemented未实现 op \'pad\' 的 PyTorch 转换功能
【发布时间】:2022-10-16 08:22:19
【问题描述】:

当我尝试使用 coremltools 将 model.ckpt 转换为核心 ML 模型时,出现此错误:

  
  File "/Users/peterpan/miniforge3/lib/python3.10/site-packages/coremltools/converters/mil/frontend/torch/ops.py", line 86, in convert_nodes
    raise RuntimeError(
RuntimeError: PyTorch convert function for op 'pad' not implemented.

这是转换代码:

   model: torch.nn.Module = make_training_model(train_config)
    state = torch.load(path, map_location=map_location)
    model.load_state_dict(state['state_dict'], strict=strict)
    model.on_load_checkpoint(state)
    model.eval()
   
    jit_model_wrapper = JITWrapper(model)
    image = torch.rand(1, 3, 120, 120)
    mask = torch.rand(1, 1, 120, 120)
    output = jit_model_wrapper(image, mask)

    device = torch.device("cpu")

    image = image.to(device)
    mask = mask.to(device)
    traced_model = torch.jit.trace(jit_model_wrapper, (image, mask), strict=False).to(device)
    model1 = ct.convert(
        traced_model,
        source='pytorch',
        inputs=[ct.ImageType(name='image',shape=image.shape), ct.ImageType(name='mask',shape=mask.shape)]
    )
    model1.save("newmodel.mlmodel")

我是python的新手。我的代码有什么问题?

【问题讨论】:

    标签: python pytorch torch coremltools


    【解决方案1】:

    降级解决了这个问题的torch版本

    【讨论】:

      【解决方案2】:

      升级到coremltools==6.0 为我解决了这个问题

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-12-12
        • 2021-04-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-08-15
        相关资源
        最近更新 更多