Hi All ,
Have been using ml model in my app.It was working awesome below iOS 13.But the same mlmodle get crashed in iOS 13 and above.Please guide me asap.I feel its a bug with Apple .PFB logs
[coreml] MLModelAsset: load failed with error Error Domain=com.apple.CoreML Code=0 "Invalid URL for .mlmodel." UserInfo={NSLocalizedDescription=Invalid URL for .mlmodel.}
2019-09-14 18:32:58.776078+0530 Testing[565:205914] [coreml] MLModelAsset: modelWithError: load failed with error Error Domain=com.apple.CoreML Code=0 "Invalid URL for .mlmodel." UserInfo={NSLocalizedDescription=Invalid URL for .mlmodel.}
Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=com.apple.CoreML Code=0 "Invalid URL for .mlmodel." UserInfo={NSLocalizedDescription=Invalid URL for .mlmodel.}:
2019-09-14 18:32:58.777056+0530 OrigoTesting[565:205914] Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=com.apple.CoreML Code=0 "Invalid URL for .mlmodel." UserInfo={NSLocalizedDescription=Invalid URL for .mlmodel.}: file ModelWrapper.swift, line 30
In My Model Wrapper file i have below code
public init(url: URL) {
print("url :\(url)")
self.model = try! TestModel(contentsOf: url)
}
This code works below iOS 13 very well.
Please guide.
I think this is a bug in iOS 13. The API seems to only accept .mlmodelc but the error message is misleading. What worked for me is passing a file-based URL instead of the URL without any scheme.
For example,
public init(url: URL) {
print("url :\(url)")
let fileURL = URL(fileURLWithPath: url.absoluteString)
self.model = try! TestModel(contentsOf: fileURL)
}