Unable to load CoreML model using MLModel.compileM

2019-08-17 17:42发布

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

But I get the error The file couldn’t be saved., the model does exist at that location.

1条回答
霸刀☆藐视天下
2楼-- · 2019-08-17 18:19

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.

See my original post. Unable to load CoreML model using MLModel.compileModel

查看更多
登录 后发表回答