部署到Core ML(翻译)

原文链接:部署到Core ML

部署到CoreML

在Turi Create中创建的目标检测模型可以很容易的部署到Core ML

在iOS12 和 macOS10.14(Turi Create 5)中部署模型

使用Turi Create 5.0+ 、iOS12 和macOS10.14,你可以通过Vision Framework直接集成目标检测模型。

你可以直接在Turi Create5中导出到Core ML,如下所示

model.export_coreml('MyDetector.mlmodel')
let mlmodel = MyDetector()
let visionModel = try VNCoreMLModel(for: mlmodel.model)
let objectRecognition = VNCoreMLRequest(model: visionModel,
                                        completionHandler: {
    (request, error) in
    guard let results = request.results else {
    return }

    for case let foundObject as VNRecognizedObjectObservation in results {
   
        let bestLabel = foundObject.labels.first! // Label with highest confidence
        let objectBounds = foundObject.boundingBox // Normalized between [0,1]
        let confidence = foundObject.confidence // Confidence for the predicted class

        // Use the computed values.
        print(bestLabel.identifier, confidence, objectBounds)
    }
})
objectRecognition.imageCropAndScaleOption = .scaleFill

有关于Core ML的集成和示例应用程序的更多细节,请查看Recognizing Objects in Live Capture小节,请注意上面链接的演示demo使用归一化的置信度,该置信度强制所有类别的得分总和为1。

  • 注意:边界框对象VNRecognizedObjectObservation.boundingBox和 Turi Create所使用的边界框定义不一样。首先,位置的坐标是在边界框左下角,而不是中心点。其次,坐标空间的原点位于图像的左下角。最后,边界框的位置坐标、宽度和高度都通过图像的尺寸归一化在[0,1]之间
  • 注意:仅仅使用了non-maximum suppression参数导出的模型(Turi Create 5.0+ 默认为true)才能与上面的例子一起使用。较旧的模型或指定了include_non_maximum_suppression = False参数的模型不会将结果作为VNRecognizedObjectObservation对象,而是将结果作为VNCoreMLFeatureValueObservation对象。而VNCoreMLFeatureValueObservation对象在上面的例子中是被忽略的。要了解如何使用VNCoreMLFeatureValueObservation对象,请继续阅读。

在iOS11 和 macOS10.13中部署模型

在iOS11和macOS10.13中部署目标检测模型,你需要执行一些额外的步骤(这些步骤已经合并到iOS12 和 macOS 10.14中)

你可以在Turi Create5中按照如下步骤导出到Core ML

model.export_coreml
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值