- Machine Learning with Swift
- Alexander Sosnovshchenko
- 247字
- 2021-06-24 18:55:01
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:

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.
- FPGA從入門到精通(實戰篇)
- Applied Unsupervised Learning with R
- 電腦維護與故障排除傻瓜書(Windows 10適用)
- 深入淺出SSD:固態存儲核心技術、原理與實戰
- Manage Partitions with GParted How-to
- Learning Game Physics with Bullet Physics and OpenGL
- 分布式微服務架構:原理與實戰
- Apple Motion 5 Cookbook
- 筆記本電腦使用、維護與故障排除從入門到精通(第5版)
- Mastering Quantum Computing with IBM QX
- USB應用開發寶典
- Learning Less.js
- UML精粹:標準對象建模語言簡明指南(第3版)
- Learning Microsoft Cognitive Services
- Practical Artificial Intelligence and Blockchain