我对CoreML有问题,因为当我希望程序验证图像时,会出现错误:
[coreml]错误Domain = com.apple.CoreML代码= 1“输入图像功能 图片与模型说明不符” UserInfo = {NSLocalizedDescription =输入图像特征图像不正确 匹配模型说明,NSUnderlyingError = 0x2807c0cf0 {Error Domain = com.apple.CoreML代码= 1“图像不是预期的类型 OneComponent8改为32ARGB” UserInfo = {NSLocalizedDescription =图像不是预期的类型 OneComponent8改为32ARGB}}} 2018-10-24 06:47:53.975118 + 0200 ognizeMyFood [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
}
如果有人能帮助我,我将不胜感激!
答案 0 :(得分:1)
该键位于错误消息中:“图像不是预期的类型OneComponent8,而是32ARGB”
您要为其提供彩色图像(kCVPixelFormatType_32ARGB
),但是模型需要灰度图像(kCVPixelFormatType_OneComponent8
)。