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
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.