gpt4 book ai didi

swift - CoreML 无法验证输入

转载 作者:行者123 更新时间:2023-11-28 14:06:13 33 4
gpt4 key购买 nike

我对 CoreML 有疑问,因为当我希望程序验证图像时出现错误:

[coreml] Error Domain=com.apple.CoreML Code=1 "Input image feature image does not match model description" UserInfo={NSLocalizedDescription=Input image feature image does not match model description, NSUnderlyingError=0x2807c0cf0 {Error Domain=com.apple.CoreML Code=1 "Image is not expected type OneComponent8, instead is 32ARGB" UserInfo={NSLocalizedDescription=Image is not expected type OneComponent8, instead is 32ARGB}}} 2018-10-24 06:47:53.975118+0200 recognizeMyFood[25848:7075048] [coreml] Failure verifying inputs.

下面是我进行图像转换时截取的代码:

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
}

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

最佳答案

关键在错误信息中:“Image is not expected type OneComponent8, instead is 32ARGB”

您为其提供彩色图像 (kCVPixelFormatType_32ARGB),但模型需要灰度图像 (​​kCVPixelFormatType_OneComponent8)。

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

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com