App is crashing due to mlmodel file url not found in iOS 13 beta and above

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.

Answered by in 396674022

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)

}

The extension of models built and bundled with your app is actually

.mlmodelc
, maybe it has something to do with that?


Also, did you check that the model is actually bundles with your app?

Yes, it bundles correctly. Maybe I will check with Xcode 11 and let you know. Till now have checked in Xcode 10.3 with iOS 13 disk image.

Hi,

Were you able to find a workaround for this issue ? I'm hitting the exact same error, CoreML seems to expect non compiled models after iOS13, but there is nothing specified in the documentation about new functions for loading mlmodelc files.


Thanks.

No not yet i have filed a bug with Apple to get help from them.Few said the compiled model should be coreml3.

Any update on this, even I am facing this issue.

Accepted Answer

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)

}

I had a similar issue with .mlmodelc, in my case the models files were corrupted over the download process, was able to delete the files and download them again and it all worked as expected

App is crashing due to mlmodel file url not found in iOS 13 beta and above
 
 
Q