无法使用MLModel.compileModel(at :)加载CoreML模型 [英] Unable to load CoreML model using MLModel.compileModel(at:)
问题描述
我正在尝试使用以下代码加载.mlmodel
文件:
I am trying to load a .mlmodel
file using the following code:
let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
var documentsUrl = paths[0]
documentsUrl.appendPathComponent("parallel.mlmodel")
do {
let compiledModelUrl = try MLModel.compileModel(at: documentsUrl)
let model = try? MLModel(contentsOf: compiledModelUrl)
} catch {
print(error.localizedDescription)
}
但是我收到错误The file couldn’t be saved.
,该模型确实存在于该位置.
But I get the error The file couldn’t be saved.
, the model does exist at that location.
推荐答案
我找到了答案.当我以调试模式将应用程序从Mac部署到iphone时,我也遇到了此问题.实际上,代码没有错,这是另外一回事.我做了两件事,首先登录icloud(icloud与开发的配置文件有关吗?),其次删除该应用程序并将其重新部署到iphone.现在解决了这个问题. 尽管我不确定哪个可以解决我的问题,但我认为这是我做的第二件事.让我知道是否有人找到背后的原因.
I found the answer. I also encountered this problem when I deploy an app to an iphone from Mac in debug mode. Actually, there is nothing wrong with the code, it is something else. I did two things, first signed in to icloud (does icloud have anything to do with its provisioning profile for development?), secondly delete the app and re-deploy the app to the iphone. It solves the problem now. Although I am not sure which one solves my problem, I assume it is the second thing I did. Let me know if anyone found the reason behind.
请参阅我的原始帖子. 无法使用MLModel.compileModel加载CoreML模型
See my original post. Unable to load CoreML model using MLModel.compileModel
这篇关于无法使用MLModel.compileModel(at :)加载CoreML模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!