-
Notifications
You must be signed in to change notification settings - Fork 659
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ML model doesn't load on background thread #611
Comments
@bhavin250495 could you share the code that you are using to run the prediction in the background? One thing to keep in mind is background mode is enabled only on CPU. You can do this by setting MLModelConfiguration.computeUnits. |
@anilkatti Thanks for replying, I tried adding MLPredcitionOptions but i don't have any problem
func predict(input:MLInput) throws -> Bool{
print("Loading model")
//Model does't load here when in background
if let model = SmartML(){
let options = MLPredictionOptions.init()
options.usesCPUOnly = true
let outputLabel = try nudgeModel.prediction(input: input:MLInput,options: options).classLabel
let status = (outputLabel == "yes") ? true : false
return status
}
return false
} |
My suggestion was to use SmartML(configuration:) method to load the model but, I did not realize that you were running this on MacOS. Based on the error, it seem like the app is having issue reading the model files from disk in the background mode. Could you share a repro case so, I can debug the root-cause? The model itself looks good. |
I am using this model on iOS , and if i share the repo to reproduce the error you will need to setup silent notifications . Could you run the inference using local timer in background to reproduce the error |
Hi all, When I inited model in foreground, or in BGProcessing mode, it's ok. |
I am looking for clear guidance in this scenario. I will update this tread. |
Signed-off-by: Ryan Russell <[email protected]> Signed-off-by: Ryan Russell <[email protected]>
🐞Describe the bug
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
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
The text was updated successfully, but these errors were encountered: