Reputation: 59
I'm having some problems setting up a Core ML model...
Xcode tells me : "init() is deprecated: Use init(configuration:) instead and handle errors appropriately."
Here is my code:
guard let model = try? VNCoreMLModel(for: MobileNetV2().model) else {
fatalError("Unable to load the model")
}
let classificationRequest = VNCoreMLRequest(model: model, completionHandler: classificationCompleteHandler)
classificationRequest.imageCropAndScaleOption = VNImageCropAndScaleOption.centerCrop
visionRequests = [classificationRequest]
loopCoreMLUpdate()
}
How can I solve that?
Thanks a lot for your answers!
Loïc
Upvotes: 0
Views: 2244
Reputation: 7892
The answer is literally in the error message: don't use the init without arguments, use init(configuration:)
to instantiate the model.
let config = MLModelConfiguration()
guard let coreMLModel = try? MobileNetV2(configuration: config),
let visionModel = try? VNCoreMLModel(for: coreMLModel.model) else {
The reason for this change is that the deprecated init()
does not have a way to tell you that loading the model may have failed.
Upvotes: 4