【问题标题】:How to setup a CoreML model?如何设置 CoreML 模型?
【发布时间】:2021-04-09 11:53:03
【问题描述】:

我在设置 Core ML 模型时遇到了一些问题...

Xcode 告诉我:“不推荐使用 init():改用 init(configuration:) 并适当地处理错误。”

这是我的代码:

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()
}

我该如何解决?

非常感谢您的回答!

洛伊克

【问题讨论】:

    标签: ios swift model coreml


    【解决方案1】:

    答案就在错误信息中:不要使用不带参数的init,使用init(configuration:) 来实例化模型。

    let config = MLModelConfiguration()
    guard let coreMLModel = try? MobileNetV2(configuration: config),
          let visionModel = try? VNCoreMLModel(for: coreMLModel.model) else {
    

    进行此更改的原因是已弃用的init() 无法告诉您加载模型可能已失败。

    【讨论】:

      猜你喜欢
      • 2019-01-12
      • 2020-06-30
      • 2020-08-25
      • 2018-01-13
      • 2019-10-18
      • 2018-07-07
      • 2021-01-14
      • 2019-12-02
      • 2020-09-30
      相关资源
      最近更新 更多