1

Tried to follow https://www.appcoda.com/core-ml-model-with-python/ To build pictures recognition I use Core ML(Turi Create) + Python + Swift(iOS).

Tried to upload the same image that I've used to train for ".mlmodel" file. Didn't help. Tried to load picture 100x100 size. The same error. What else can I try?

Output:

2018-04-17 20:54:19.076605+0200 [2516:1111075] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /private/var/containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles

2018-04-17 20:54:19.077580+0200 [2516:1111075] [MC] Reading from public effective user settings.

2018-04-17 20:54:54.795691+0200 [2516:1111075] [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=0x1c024cf90 {Error Domain=com.apple.CoreML Code=1 "Image is not valid width 227, instead is 224" UserInfo={NSLocalizedDescription=Image is not valid width 227, instead is 224}}}

2018-04-17 20:54:54.795728+0200 [2516:1111075] [coreml] Failure verifying inputs.

Due to request from comments:

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)
}
4

1 回答 1

1

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

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

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

于 2018-04-18T08:28:33.590 回答