Getting 'init()' is deprecated: Use init(configuration:) instead and handle errors appropriately.

I am trying to make an Image Classifier but I keep getting a warning 'init()' is deprecated: Use init(configuration:) instead and handle errors appropriately. I was wondering if it matters because the app gets made and the classifier works. Just wondering what the warning means.

Thanks in advance!

Answered by ahamilton454 in 683767022

This is simply a deprecation warning saying that the method you are using to initialize the CoreML model will not be supported in the future. I would suggest updating your code to use the more recent initialization technique as follows.

let model: ImageClassifierModel = try! ImageClassifierModel(configuration: .init())

or

let model: ImageClassifierModel = try! ImageClassifierModel(configuration: MLModelConfiguration())

Although, I would also handle the error if the model fails to initialize.

Accepted Answer

This is simply a deprecation warning saying that the method you are using to initialize the CoreML model will not be supported in the future. I would suggest updating your code to use the more recent initialization technique as follows.

let model: ImageClassifierModel = try! ImageClassifierModel(configuration: .init())

or

let model: ImageClassifierModel = try! ImageClassifierModel(configuration: MLModelConfiguration())

Although, I would also handle the error if the model fails to initialize.

Getting 'init()' is deprecated: Use init(configuration:) instead and handle errors appropriately.
 
 
Q