ML model doesn't load on background thread
- Dominant language
- Python
- Stars
- 5.4k
- Forks
- 850
- Avg merge
- 4d 5h
- Merged PRs (30d)
- 10
Description
## 🐞Describe the bug
- The inference runs fine when the app is in foreground but when it goes background, and tries to run inference gets crashed or takes long time to load model `MLModel.init()`
## Trace
2020-01-31 12:17:10.135653+0530 ********** [3505:875445] [coreml] Error in adding network -1.
2020-01-31 12:17:10.139437+0530 ********** [3505:875445] [coreml] MLModelAsset: load failed with error Error Domain=com.apple.CoreML Code=0 "Error in declaring network." UserInfo={NSLocalizedDescription=Error in declaring network.}
2020-01-31 12:17:10.140146+0530 ********** [3505:875445] [coreml] MLModelAsset: modelWithError: load failed with error Error Domain=com.apple.CoreML Code=0 "Error in declaring network." UserInfo={NSLocalizedDescription=Error in declaring network.}
Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=com.apple.CoreML Code=0 "Error in declaring network." UserInfo={NSLocalizedDescription=Error in declaring network.}: file ML.swift, line 105
## To Reproduce
- Just load the model when app in background
```
Default generated file to run ML model
/// Construct a model that automatically loads the model from the app's bundle
convenience init() {
try! self.init(contentsOf: model.urlOfModelInThisBundle)
}
```
[demoModel.mlmodel.zip](https://github.com/apple/coremltools/files/4137981/demoModel.mlmodel.zip)
## System environment (please complete the following information):
- coremltools version (e.g., 3.0b5):
- OS: MAC OS
- macOS version (if applicable): 14
- XCode version (if applicable): 11.3.1]
- How you install python (anaconda, virtualenv, system): system
- python version (e.g. 3.7): 3.7
- any other relevant information: 2.3
- keras version: 2.3
Contributor guide
Assessment
This issue has not been assessed yet.