【问题标题】:Why Can't I Use Images With CoreMLTools In Python 3?为什么我不能在 Python 3 中使用带有 CoreMLTools 的图像?
【发布时间】:2020-12-08 18:00:39
【问题描述】:

我有一个程序,我需要使用 coremltools 来预测带有图像的东西,但是当我通过它输入图像时它不起作用。

我的代码是:

import coremltools
from PIL import Image

img=Image.open('/path/to/jpg/file.jpg')
model=coremltools.models.MLModel('/path/to/mlmodel/file.mlmodel')
model.predict({'d':img})

然后它返回:

  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/coremltools/models/model.py", line 329, in predict
    return self.__proxy__.predict(data, useCPUOnly)
RuntimeError: {
    NSLocalizedDescription = "Predicted feature named 'classLabel' was not output by pipeline";
}

【问题讨论】:

    标签: python-3.8 coremltools macos-big-sur


    【解决方案1】:

    我刚遇到这个问题,对我来说,我没有通过正确的关键字访问。我的电话是

    model.predict( {"img": img } )
    

    但是当我打印模型的时候,我看到了这段

    input {
      name: "image"
      shortDescription: "Input image to be classified"
      ....
    }
    

    当我改为:

    model.predict( {"image": img} )
    

    一切正常。不知道还有什么可能触发该错误,因为它看起来很笼统且无用,因此也许它也可能是您的其他参数中的错误。

    【讨论】:

      猜你喜欢
      • 2017-09-19
      • 2012-01-06
      • 1970-01-01
      • 2023-03-03
      • 2021-11-08
      • 2016-09-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多