【问题标题】:CoreML cannot verify inputsCoreML 无法验证输入
【发布时间】:2019-03-28 10:00:52
【问题描述】:

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

[coreml] Error Domain=com.apple.CoreML Code=1 "输入图片特征 图片与型号描述不符” UserInfo={NSLocalizedDescription=输入图像特征图像不 匹配模型描述,NSUnderlyingError=0x2807c0cf0 {Error Domain=com.apple.CoreML Code=1 "图片不是预期类型 OneComponent8,而是 32ARGB" UserInfo={NSLocalizedDescription=图像不是预期类型 OneComponent8, 而不是 32ARGB}}} 2018-10-24 06:47:53.975118+0200 identifyMyFood[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
}

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

【问题讨论】:

    标签: swift coreml


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2018-06-08
      • 2018-09-27
      • 2015-07-23
      • 1970-01-01
      • 2020-04-15
      • 2023-03-11
      • 2021-01-19
      • 2020-11-22
      • 1970-01-01
      相关资源
      最近更新 更多