在iOS11上推出了CoreML和架构在CoreML之上的Vision, 这样为CNN(卷积神经网络)在iOS设备上的应用铺平了道路。
将CoreML模型加载到App
让你的App集成CoreML模型非常简单, 将模型文件(*.mlmodel)拖进工程即可. 在Xcode中可以看到此模型的描述.
Xcode可以为此模型文件自动生成一个可以被使用的对象, 此预测人年龄的CNN的自动生成代码如下(Swift)
//
// AgeNet.swift
//
// This file was automatically generated and should not be edited.
//
import CoreML
/// Model Prediction Input Type
@available(OSX 13.0, iOS 11.0, tvOS 11.0, watchOS 4.0, *)
class AgeNetInput : MLFeatureProvider {
/// An image with a face. as color (kCVPixelFormatType_32BGRA) image buffer, 227 pixels wide by 227 pixels high
var data: CVPixelBuffer
var featureNames: Set<String> {
get {
return ["data"]
}
}
func featureValue(for featureName: String) -> MLFeatureValue? {
if (featureName == "data") {
return MLFeatureValue(pixelBuffer: data)
}
return nil
}
init(data: CVPixelBuffer) {
self.data &#