I have an app in the App Store and I get its error logs from Crashlytics. One of the most common errors that users get (and one that I lost badly to reproduce) occurs when initializing the CoreML model in my project. This is how I initialize the model:
class VisionManager: NSObject {
The error, as seen from Crashlytics, is as follows:
fatal error: 'try!' the expression unexpectedly caused an error: Error Domain = com.apple.CoreML Code = 0 "Error declaring the network." UserInfo = {NSLocalizedDescription = error during network declaration.}: File /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-900.0.65.2/src/swift/stdlib/public/core/ErrorType.swift, line 181
And the stack trace shows that an error occurs when the guard block is executed. In fact, it goes deeper and shows that the error was thrown inside the static initialization at the top when the initializer was called. The initializer, along with the entire MobileNet.swift class, is automatically created and looks like this:
init(contentsOf url: URL) throws { self.model = try MLModel(contentsOf: url) }
It seems obvious that the error was caused by the init(contentsOf url: URL) method init(contentsOf url: URL) . However, since this is a generated file, I believe that I cannot do this to fix this error.
One of the possibilities is that the compiled .mlmodelc file is somehow not copied to the package, and when we try to initialize the MobileNet object using this URL , we get a non-empty error. Is it possible?
Any ideas or pointers to this issue are welcome.
source share