我对CoreML有问题,因为当我想让程序验证图像时,会出现一个错误:
[coreml]Error Domain=com.apple.coreml Code=1“输入图像功能
图像与模型描述不匹配“
UserInfo={NSLocalizedDescription=输入图像功能图像不
匹配模型描述,NSUnderlyingError=0x2807c0cf0{错误
Domain=com.apple.CoreML Code=1“图像不是预期类型
而OneComponent8是32ARGB“
UserInfo={NSLocalizedDescription=图像不是预期的类型
而OneComponent8是32ARGB}}2018-10-24 06:47:53.975118+0200
recognizeMyFood[25848:7075048][coreml]验证输入失败。
下面是一个截取的代码,其中我有图像转换:

UIGraphicsBeginImageContextWithOptions(CGSize(width: 343, height: 447), true, 2.0)
image.draw(in: CGRect(x: 0, y: 0, width: 343, height: 447))
let newImage = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()

let attrs = [kCVPixelBufferCGImageCompatibilityKey: kCFBooleanTrue, kCVPixelBufferCGBitmapContextCompatibilityKey: kCFBooleanTrue] as CFDictionary
var pixelBuffer : CVPixelBuffer?
let status = CVPixelBufferCreate(kCFAllocatorDefault, Int(newImage.size.width), Int(newImage.size.height), kCVPixelFormatType_32ARGB, attrs, &pixelBuffer)
guard (status == kCVReturnSuccess) else {
    return
}

如果有人能帮助我,我将不胜感激!

最佳答案

密钥在错误消息中:“图像不是预期的类型OneComponent8,而是32ARGB”
您为它提供了一个彩色图像(kCVPixelFormatType_32ARGB),但模型需要一个灰度图像(kCVPixelFormatType_OneComponent8)。

关于swift - CoreML无法验证输入,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52961342/

10-10 21:33