swift - 从 Firebase 下载/保存远程 ML 模型时出错
问题描述
我在一个反应原生项目中使用 MLKit 和 iOS。
基本上使用此代码:https ://firebase.google.com/docs/ml/ios/label-images-with-automl
它曾经工作正常,但现在我收到此错误:
downloadModel: notificationDidFail:
name = com.google.mlkit.notif.model-download-did-fail,
object = Optional(<MLKModelDownloader: 0x281a86300>),
userInfo = Optional([AnyHashable("MLKModelDownloadUserInfoKeyError"): Error Domain=com.google.mlkit Code=2 "Failed to save AutoML remote model labels file." UserInfo={NSLocalizedDescription=Failed to save AutoML remote model labels file.}, AnyHashable("MLKModelDownloadUserInfoKeyRemoteModel"): name: lepidoptera_underside])
Xcode 打印: [MLKit][I-MLK018012] AutoML 远程模型推理信息不包含标签
一种模型似乎比其他模型更有效。
这被执行:
NotificationCenter.default.addObserver(
forName: .mlkitModelDownloadDidFail,
object: nil,
queue: nil
) { notification in
self.failed("downloadModel: notification error: \(notification)")
}
整个下载模型功能:
func downloadModel() {
guard let remoteModel = remoteModel else {
failed("downloadModel: remoteModel error")
return
}
let downloadConditions = ModelDownloadConditions(
allowsCellularAccess: true,
allowsBackgroundDownloading: true
)
_ = ModelManager.modelManager().download(
remoteModel,
conditions: downloadConditions
)
NotificationCenter.default.addObserver(
forName: .mlkitModelDownloadDidSucceed,
object: nil,
queue: nil
) { [weak self] notification in
guard let strongSelf = self,
let userInfo = notification.userInfo,
let model = userInfo[ModelDownloadUserInfoKey.remoteModel.rawValue]
as? RemoteModel,
model.name == strongSelf.modelName
else { return }
strongSelf.createLabeler()
}
NotificationCenter.default.addObserver(
forName: .mlkitModelDownloadDidFail,
object: nil,
queue: nil
) { notification in
self.failed("downloadModel: notification error: \(notification)")
}
}
解决方案
提供的文档 ( https://firebase.google.com/docs/ml/ios/label-images-with-automl ) 包含过时的信息。ML Kit 在其最新版本中已完全弃用并删除了该GoogleMLKit/ImageLabelingAutoML
pod。该吊舱现在被GoogleMLKit/ImageLabelingCustom
吊舱取代。最新版本的MLKitImageLabelingCustom
pod 是1.2.0
. 请参阅此处的完整迁移指南:
https://developers.google.com/ml-kit/vision/image-labeling/automl/migrate-automl
推荐阅读
- javascript - 当通过 webpack 包含 socket.io 时,获取`Uncaught ReferenceError: io is not defined`
- qt - QML - 如何将动作附加到信号处理程序?
- python-3.x - Cannot install requirements file after reinstalling python 3.7.3
- angular - 在未保存的更改弹出“取消点击”需要在下拉菜单中设置以前的值
- computer-science - 关于正则表达式的问题
- java - 共享界面的正确方法是什么?
- testing - 是什么限制了 Gradle 构建中的活跃工人数量?
- .net - 数据库优先 - Mono 上的 EF6
- javascript - 原子简单的console.log?
- java - 为 Spring Boot 应用程序捕获堆转储