0

我有一个程序,我需要使用 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";
}
4

1 回答 1

0

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

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

但是当我打印模型时,我看到了这个部分

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

当我改为:

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

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

于 2020-08-21T16:20:43.397 回答