官术网_书友最值得收藏!

Importing the Core ML model into an iOS project

Create a new iOS project and drag and drop the DecisionTree.mlmodel into a project tree in Xcode. Click on it to see a machine learning model navigator screen:

Figure 2.11: Machine learning navigator screen

On this screen, you can find a familiar model description, model type (pipeline by some reason, in this case), the name of the Swift class that represents the model in the app, and lists of inputs and outputs. If you click on the small arrow next to the class name in the Model Class section, the autogenerated file DecisionTree.swift is opened. This reminds a Core Data framework, where you have autogenerated files for NSMangedObject subclasses. DecisionTree.swift contains three classes:

  • DecisionTreeInput: MLFeatureProvider, contains the input features (six of them, all Double).
  • DecisionTreeOutput: MLFeatureProvider, contains class label and class probability.
  • DecisionTree: NSObject, the class of the model itself. It contains methods for initialization and making predictions.

The method init(contentsOf: url) allows to replace the model in runtime, but only if you preserve the input and output structure. For example, this is how the model is loaded from the file in the bundle:

let bundle = Bundle.main 
let assetPath = bundle.url(forResource: "DecisionTree", withExtension:"mlmodelc") 
let sklDecisionTree = DecisionTree(contentsOf: assetPath!) 

In a same way, you can create a model with the content of a remote URL.

Drag and drop the RandomForest.ml model to the project to also compare accuracy of the models on the iOS.

主站蜘蛛池模板: 视频| 延庆县| 云南省| 如东县| 玛多县| 益阳市| 兰西县| 九龙城区| 永州市| 辽阳县| 登封市| 册亨县| 阿拉善右旗| 甘泉县| 新巴尔虎左旗| 临桂县| 邳州市| 奇台县| 中西区| 香河县| 拉孜县| 黎平县| 同江市| 甘泉县| 宜宾市| 邮箱| 鄄城县| 孟州市| 延庆县| 炉霍县| 准格尔旗| 肇州县| 富源县| 巫溪县| 绥芬河市| 麻江县| 保亭| 鹰潭市| 页游| 汉沽区| 景泰县|