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