试图按照https://www.appcoda.com/core-ml-model-with-python/ Build 图片识别我使用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 = } } 2018-04-17 20:54:54.795728 0200 [2516:1111075] [coreml]验证输入失败 .
由于评论请求:
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)
}
1 回答
错误消息字面上说明错误的原因是:
您正在使用的模型(我怀疑它是SqueezeNet)期望输入图像大小为227x227,而不是224x224或任何其他大小 .