【问题标题】:Coreml, Failure verifying inputs. Image is not validCoreml,失败验证输入。图片无效
【发布时间】:2018-09-27 21:04:39
【问题描述】:

尝试关注https://www.appcoda.com/core-ml-model-with-python/ 为了构建图片识别,我使用 Core ML(Turi Create) + Python + Swift(iOS)。

尝试上传我用来训练“.mlmodel”文件的相同图像。 没有帮助。尝试加载 100x100 大小的图片。同样的错误。我还能尝试什么?

输出:

2018-04-17 20:54:19.076605+0200 [2516:1111075] [MC] 系统组 systemgroup.com.apple.configurationprofiles 路径的容器是 /private/var/containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles

2018-04-17 20:54:19.077580+0200 [2516:1111075] [MC] 阅读自 公开有效的用户设置。

2018-04-17 20:54:54.795691+0200 [2516:1111075] [coreml] 错误 Domain=com.apple.CoreML Code=1 "输入图像特征图像不 匹配模型描述" UserInfo={NSLocalizedDescription=输入图像 特征图像与模型描述不匹配, NSUnderlyingError=0x1c024cf90 {错误域=com.apple.CoreML 代码=1 “图像的宽度不是 227,而是 224” UserInfo={NSLocalizedDescription=图像不是有效宽度 227,而是 是 224}}}

2018-04-17 20:54:54.795728+0200 [2516:1111075] [coreml] 失败 验证输入。

应cmets的要求:

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String: Any]) {
    if let image = info[UIImagePickerControllerOriginalImage] as? UIImage {
        previewImg.image = image

        if let buffer = image.buffer(with: CGSize(width: 224, height: 224)) {

            guard let prediction = try? mlModel.prediction(image: buffer) else {
                fatalError("Unexpected runtime error")
            }

            descriptionLbl.text = prediction.foodType
            print(prediction.foodTypeProbability)
        } else {
            print("failed buffer")
        }
    }

    dismiss(animated: true, completion: nil)
}

【问题讨论】:

  • 发布您的代码,尤其是func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any])
  • 尝试从教程加载标准训练模型......它有效。 95mb 的重量。我的 - 5mb。但我发现更多图像+更好的分辨率。没有帮助:(同样的问题......

标签: ios swift neural-network coreml turi


【解决方案1】:

错误信息从字面上说明了错误的原因是什么:

2018-04-17 20:54:54.795691+0200 [2516:1111075] [coreml] 错误 Domain=com.apple.CoreML Code=1 "输入图像特征图像不 匹配模型描述" UserInfo={NSLocalizedDescription=输入图像 特征图像与模型描述不匹配, NSUnderlyingError=0x1c024cf90 {错误域=com.apple.CoreML 代码=1 “图像的宽度不是 227,而是 224” UserInfo={NSLocalizedDescription=图像不是有效宽度 227,而是 是 224}}}

您正在使用的模型(我怀疑它是 SqueezeNet)需要大小为 227x227 的输入图像,而不是 224x224 或任何其他大小。

【讨论】:

  • 谢谢 :) 奇怪...没想到这么简单的错误,因为它是从 Appcoda.com 完成的并且应该自动调整大小...但是刚刚更改为:if let buffer = image.buffer(with: CGSize(width:224, height:224)) 到 if let buffer = image.buffer(with: CGSize(width:227, height:227)) 现在可以了。
猜你喜欢
  • 2018-06-08
  • 2019-03-28
  • 1970-01-01
  • 2018-12-15
  • 2012-05-30
  • 1970-01-01
  • 1970-01-01
  • 2013-12-03
  • 2012-02-01
相关资源
最近更新 更多