CoreML - 设备模型训练

CoreML - On device model training

我目前正在创建一个 hello world,以便大致了解 CoreML 和 CreateML 的强大功能。我的目标是在我的 hello world 项目中使用 Apples data table example,以便使用作者、页数和标题等给定参数预测歌词的类型:

let data: [String: MLDataValueConvertible] = [
    "title": ["Alice in Wonderland", "Hamlet", "Treasure Island", "Peter Pan"],
    "author": ["Lewis Carroll", "William Shakespeare", "Robert L. Stevenson", "J. M. Barrie"],
    "pageCount": [124, 98, 280, 94],
    "genre": ["Fantasy", "Drama", "Adventure", "Fantasy"]
]

我能够使用 CreateML 在 playground 中使用这些额外的代码行创建一个 mlmodel:

let bookTable = try MLDataTable(dictionary: data)
let genreRegressor = try MLRegressor(trainingData: bookTable, targetColumn: "genre")
let meta = MLModelMetadata(author: "John Doe", shortDescription: "A model used to determine the genre of a book.", version: "1.0")
try genreRegressor.write(to: URL(fileURLWithPath: "/Path/MyModel.mlmodel"), metadata: meta)

通过这种方式,您可以提供标题、作者以及页数等输入,模型将使用以下代码行预测类型作为输出:

let model = MyModel().model

// Create the input
let modelInput = MyModelInput(author: "Mark Twain", title: "Tom Sawyer", pageCount: 245)

// Predict the genre
let modelOutput = try? model.prediction(from: modelInput)
let genre = modelOutput?.featureValue(for: "genre")
print(genre)

现在我想在设备上创建/训练这个模型,以便每次用户在应用程序中添加新数据时创建一个新模型或更新现有模型。我将代码粘贴到我的应用程序中,但不幸的是,所需的 CreateML 框架在设备上不可用。

我阅读了 tabular classification and on device training as well as tried the emoji intelligence example but I wasn't able to create my own on device tabular classification unfortunately. But through the information I was able to gather from these articles, it looks like it should be possible because the data set is very small and the calculations needed are very basic and fast. Existing examples like the emoji intelligence, TouchID or the Photos App are showing that it must be possible

如果有人有示例或提示如何对任何示例(还有图像分类等)进行设备上训练,我将非常高兴,我不仅仅关注表格数据。

提前致谢!

目前您的选择是:

  • 使用 Metal Performance Shaders 在设备上训练
  • 编写自己的训练代码

两者都不兼容 Core ML(尽管如果您真的想要,您可以编写自己的 mlmodel 文件,然后在设备上编译它)。