Core ML and Vision

来源:互联网 发布:征服者数据更新 编辑:程序博客网 时间:2024/05/12 22:59

Vision

Apply high-performance image analysis and computer vision techniques to identify faces, detect features, and classify scenes in images and video.

应用场景:

Face Detection and Recognition
Machine Learning Image Analysis
Barcode Detection
Image Alignment Analysis
Text Detection
Horizon Detection

支持的图片类型:

CVPixelBufferRefCGImageRefCIImageNSURLNSData

几乎涵盖了 iOS 中图片相关的 API,很强大。

使用到的类:

VNCoreMLModel

A container for a Core ML model used with Vision requests.

VNCoreMLRequest

An image analysis request that uses a Core ML model to process images.

VNClassificationObservation

Scene classification information produced by an image analysis request.

VNPixelBufferObservation

An output image produced by a Core ML image analysis request.

VNImageRequestHandler

An object that processes one or more image analysis requests pertaining to a single image.

总结

基于 Core ML 框架,Apple 提供了一个高性能的视觉处理技术 Vision,它更像是一个工具库,对一些高频场景进行了封装,比如人脸、条形码、矩形和文字等,这些基于底层 API 封装的高级功能可以帮助开发者高效地完成特定的功能。

参考博客:http://yulingtianxia.com/blog/2017/06/19/Core-ML-and-Vision-Framework-on-iOS-11/

Core ML

框架层级图:

这里写图片描述
(侵删)

使用原理:

这里写图片描述
(侵删)

转换Core ML模型

支持ML类型:

Core ML 支持 DNN,RNN,CNN,SVM,Tree ensembles,Generalized linear models,Pipeline models 等ML模型
这里写图片描述

转换方法:

苹果提供了一个 Python 工具coremltools,可以将业内一些常用的机器学习框架导出的 Model 转成 MLMODEL 文件。代码会编译成可执行二进制文件,而 MLMODEL 会编译成 Bundle 文件,在代码文件中可以直接调用 MLMODEL 生成的类。

比如,如果模型是用Caffe创建的,那么将 Caffe 模型(.caffemodel)传递给coremltools.converters.caffe.convert:

import coremltools coreml_model = coremltools.converters.caffe.convert('my_caffe_model.caffemodel')

然后将所得到的模型保存为 Core ML 模型格式:

coreml_model.save('my_model.mlmodel')

当你需要转换一个不在上表中的格式的模型时,也可以创建你自己的转换工具。

编写你自己的转换工具涉及到将你的模型的输入、输出和架构的表示(representation)翻译成 Core ML 模型格式。你需要定义该模型架构的每一层以及它们与其它层的连接。使用 Core ML Tools 提供的转换工具为例;它们演示了通过第三方工具创建的多种类型的模型被转换成 Core ML 模型格式的方法。

注:Core ML 模型格式是由一些协议缓冲文件(protocol buffer files)定义的,具体描述请参阅:https://developer.apple.com/machine-learning