Catalyst 的 ML 构建错误(Xcode 12 GM)

Zso*_*ker 8 ios swift coreml ios14 xcode12

还有其他人对 ML 模型的 GM 版本有问题并且有解决方案吗?我收到以下错误:

Type 'MLModel' has no member '__loadContents'

我已经清理了项目+删除了派生数据(这是一个放在派生数据文件夹中的生成文件)

我注意到该方法不应该用于我使用的 mac OS 10.15,但出于某种原因它在那里。

我还注意到这个 API 仍处于测试阶段,而 GM 是生产版本?https://developer.apple.com/documentation/coreml/mlmodel

我应该重新生成 ML 模型吗?

代码错误

小智 7

造成这种情况的根本原因是:

Xcode 12.0 GM 中的 CoreML 编译器生成的代码只有在 macOS BigSur 上可用的符号导致编译问题。如果目标是使用 Xcode 12.0 构建催化剂或仅限 macOS 的应用程序

修复步骤:

  1. 在您的目标构建设置中,您可以将 COREML_CODEGEN_LANGUAGE 设置为“无”
  2. 打开终端然后转到您的 .mlmodel 文件夹
  3. 输入“xcrun coremlcompiler generate <YourModel.mlmodel> --language Swift”。
  4. 这将在同一文件夹中创建 <YourModel.swift> 文件。
  5. 打开 Xcode 并在您的项目中添加 <YourModel.swift>。
  6. 单击 <YourModel.swift> 并注释掉编译器抱怨的方法。

就我而言,我注释掉:

class func load(contentsOf modelURL: URL, configuration: MLModelConfiguration = MLModelConfiguration(), completionHandler handler: @escaping (Swift.Result<Nudity, Error>) -> Void)
Run Code Online (Sandbox Code Playgroud)

和

class func load(configuration: MLModelConfiguration = MLModelConfiguration(), completionHandler handler: @escaping (Swift.Result<Nudity, Error>) -> Void)
Run Code Online (Sandbox Code Playgroud)

修复swift文件的方法。