问题
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 :
- In your targets build settings you can set COREML_CODEGEN_LANGUAGE to "None"
- Open terminal then go to where your .mlmodel folder
- Type "xcrun coremlcompiler generate <YourModel.mlmodel> --language Swift ."
- This will create <YourModel.swift> file in same folder.
- Open Xcode and add <YourModel.swift> in your project.
- 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