简体   繁体   English

我们可以使用用户数据在 iOS 设备上训练 CreateML 吗?

[英]Can we train CreateML on iOS device using user's data?

I understand that we can train ML model on macOS with Xcode CreateML GUI, as well as in macOS Playground.我知道我们可以在 macOS 上使用 Xcode CreateML GUI 以及 macOS Playground 训练 ML model。 The problem I had, is to train a similar model on user's device, using their own data.我遇到的问题是使用用户自己的数据在用户设备上训练类似的 model。 I'm wondering if it's possible?我想知道这是否可能?

Can we train CreateML text classifier on user's device?我们可以在用户设备上训练 CreateML 文本分类器吗? I had did some research but could not find an answer.我做了一些研究,但找不到答案。 Mostly people are talking about deploy a trained model to iOS. But I wanna to train on iOS.大多数人都在谈论将训练有素的 model 部署到 iOS。但我想在 iOS 上训练。

PsI also had a look at the updatable CoreML model. Which does not seems to support text classifier. PsI 还查看了可更新的 CoreML model。它似乎不支持文本分类器。 They only supports KNN model as well as shallow neural.network.它们仅支持 KNN model 以及浅层神经网络。

More Specifically.进一步来说。 Can we even use MLTextClassifier this to create Model on iOS?我们甚至可以使用MLTextClassifier在 iOS 上创建 Model 吗? The conflict information is that, on Apple's CreateML main page, it says you need to train on Mac.冲突信息是,在Apple的CreateML主页上,它说你需要在Mac上训练。 But this API seems to indicate that it supports iOS, which really confuses me.但是这个API好像表示支持iOS,真是让我很疑惑。

init(trainingData: [String : [String]], parameters: MLTextClassifier.ModelParameters) 

The CreateML module does work on iOS (since iOS 15). CreateML模块确实适用于 iOS(自 iOS 15 起)。 It just doesn't work on iOS simulator.它只是不适用于 iOS 模拟器。

You can surround all your training code with您可以将所有训练代码包围起来

#if canImport(CreateML)

...

#endif

so that it only runs when you are on a real device.以便它仅在您使用真实设备时运行。 Admittedly, this is rather inconvenient...不可否认,这很不方便......

As for how to use the CreateML API, you can follow the guide here .至于如何使用CreateML API,可以参考这里的指南。 The code would look something like this.代码看起来像这样。 Note that I've updated some of the deprecated (since iOS 16) code in the guide to use the newest APIs.请注意,我已经更新了指南中一些已弃用(自 iOS 16 起)的代码,以使用最新的 API。

import CoreML
import CreateML
import NaturalLanguage
import TabularData

// training...
let sentimentClassifier = try MLTextClassifier(trainingData: [
    "positive": [...],
    "negative": [...],
    "neutral": [...],
])

// write to file for later use...
let metadata = MLModelMetadata(author: "John Appleseed",
                               shortDescription: "A model trained to classify movie review sentiment",
                               version: "1.0")
try sentimentClassifier.write(to: URL(fileURLWithPath: "/path/to/save/SentimentClassifier.mlmodel"),
                              metadata: metadata)
// or use it immediately:
print(sentimentClassifier.prediction(from: "foo bar baz"))

//... at some later point

let model = try MLModel(contentsOf: URL(fileURLWithPath: "/path/to/save/SentimentClassifier.mlmodel"))
let nlModel = try NLModel(mlModel: model)
print(nlModel.predictedLabel(for: "foo bar baz") ?? "no label")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 iOS:如果设备越狱,我们可以访问应用程序的文档文件夹吗 - iOS : Can we access app's documents folder if device is jailbroken 我们有多少种方法可以访问用户的位置iOS? - How many ways we can access user's location iOS? 如何检测用户的(iOS 设备)是否在欧洲? - How to detect is user's (iOS device) is in Europe? 如何在iOS SDK中检查用户的设备 - How to check user's device in iOS SDK 我们如何使用机器人框架在设备上自动化已安装的 ios 应用程序? - How can we automate already installed ios app on device using robot framework? 如何访问我们的iOS应用程序的用户数据? - How can I access a user's data for our iOS app? 在iOS设备上安全存储个人用户数据 - Secure Storage of Personal User Data on iOS Device 我的应用程序如何识别用户的iOS设备上存在哪些社交应用程序? - How can my app identify which social apps are present on user's iOS device? 如何注册用户的ios设备以从Ap​​pDelegate以外的其他地方接收推送消息? - How can I register user's ios device for receiving push messages from place other than AppDelegate? 使用iOS SDK和完整的Cocoa Touch / Objective-C代码确定用户的设备 - Determine user's device using iOS SDK and full Cocoa Touch / Objective-C code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM