ML Build error for Catalyst (Xcode 12 GM)

岁酱吖の 提交于 2021-01-02 06:07:21

问题


Anyone else having issues with the GM release with ML models and has a solution for this? I get the following error:

Type 'MLModel' has no member '__loadContents'

I have cleaned the Project + deleted derived data (this is a generated file that is put into the derived data folder)

I notice that the method should not be there for mac OS 10.15 which I use, but it there for some reason.

I also noticed that this API is still in beta while the GM is a production build? https://developer.apple.com/documentation/coreml/mlmodel

Should I regenerate the ML model?


回答1:


Root cause of this is :

CoreML compiler in Xcode 12.0 GM is generating code that has symbols available only on macOS BigSur causing the compilation issue. If the goal is to build a catalyst or macOS-only app with Xcode 12.0

Steps to fix :

  1. In your targets build settings you can set COREML_CODEGEN_LANGUAGE to "None"
  2. Open terminal then go to where your .mlmodel folder
  3. Type "xcrun coremlcompiler generate <YourModel.mlmodel> --language Swift ."
  4. This will create <YourModel.swift> file in same folder.
  5. Open Xcode and add <YourModel.swift> in your project.
  6. Click <YourModel.swift> and comment out method that compiler complains.

In my case I comment out :

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

and

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

methods to fix swift file.



来源:https://stackoverflow.com/questions/63917164/ml-build-error-for-catalyst-xcode-12-gm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!