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)
}
maxwell
  • 3,788
  • 6
  • 26
  • 40
J A S K I E R
  • 1,976
  • 3
  • 24
  • 42
  • 1
    Post your code, particularly for `func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any])` – beyowulf Apr 17 '18 at 20:26
  • Tried to load standart trained model from tutorial ... it works. The weight if 95mb. My - 5mb. But I've found more images + better resolutions. Didn't help :( The same issue ... – J A S K I E R Apr 18 '18 at 08:25

1 Answers1

1

The error message literally says what the cause of the error is:

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

The model you're using (I suspect it's SqueezeNet) expects input images of size 227x227, not 224x224 or any other size.

Matthijs Hollemans
  • 7,706
  • 2
  • 16
  • 23
  • Thanks :) Strange ... didn't expect so simple error, because it is being done from Appcoda.com and supposed to be sized automatically ... However just changed from: if let buffer = image.buffer(with: CGSize(width:224, height:224)) to if let buffer = image.buffer(with: CGSize(width:227, height:227)) And it works now. – J A S K I E R Apr 18 '18 at 08:45