SVS
SVS

Reputation: 21

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

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.

Upvotes: 2

Views: 1015

Answers (2)

Ronen Michael Harati
Ronen Michael Harati

Reputation: 61

Use

URL(fileURLWithPath: modelDestination)

instead of

URL(string: modelDestination)

when creating the compiled url.

Upvotes: 0

Seb
Seb

Reputation: 1686

The model will get compiled, when you bundle your app. For iOS 13 you have to search for .mlmodelc in your bundle, the .mlmodel file doesn't exist on your iPhone.

Upvotes: 3

Related Questions