Classifing user activity using CoreML in background mode

Viewed 131

I want to execute CoreML request always even when app is in background. I followed an article on Activity Classification with Create ML, CoreML3. It is working well in foreground but stops working for background mode. How can I add background support for this app. Is it possible to classify user activity using CoreML when app is back-grounded?

As a workaround, I added location manager for background support. Location manager is working as expected for background. But still activity classification request is returning nil.

Activity Classification with Create ML: https://medium.com/skafosai/activity-classification-with-create-ml-coreml3-and-skafos-part-2-734f1ea2f6e

1 Answers

Finally I found a solution that works on background. I was getting this issue for

Insufficient Permission (to submit GPU work from background)

I configured MLModelConfiguration to cpuOnly to fix this issue.

    let activityModel: MyActivityClassifier = {
    do {
        let config = MLModelConfiguration()
        config.computeUnits = .cpuOnly
        return try MyActivityClassifier(configuration: config)
    } catch {
        print(error)
        fatalError("Couldn't create MyActivityClassifier")
    }
}()
Related