【问题标题】:New error running MLModels in swift after Xcode 12 updateXcode 12 更新后快速运行 MLModel 的新错误
【发布时间】:2021-01-06 11:02:51
【问题描述】:

升级到 Xcode 12 和 Swift 5.3 后,我的 MLmodel 似乎不再正常工作,我之前没有遇到任何问题。我确定这是一个简单的修复,我只是不明白如何修复。

let WpredictionModel = _14Win()

 func calculateWin() {
    guard let prediction = try? WpredictionModel.prediction(//all of my input data) else {
        fatalError("Unexpected runtime error.")
    }

我收到了错误 'init()' 已弃用:改用 init(configuration:) 并适当地处理错误。 在 WpredictionModel 声明之后。

我也认为这是一个错误。

 @available(macOS 11.0, iOS 14.0, tvOS 14.0, watchOS 7.0, *)
    class func load(contentsOf modelURL: URL, configuration: MLModelConfiguration = MLModelConfiguration(), completionHandler handler: @escaping (Swift.Result<_14Win, Error>) -> Void) {
        MLModel.__loadContents(of: modelURL, configuration: configuration) { (model, error) in
            if let error = error {
                handler(.failure(error))
            } else if let model = model {
                handler(.success(_14Win(model: model)))
            } else {
                fatalError("SPI failure: -[MLModel loadContentsOfURL:configuration::completionHandler:] vends nil for both model and error.")
            }
        }
    }

【问题讨论】:

    标签: swift xcode mlmodel


    【解决方案1】:

    克里斯。 我昨天更新Xcode12后也遇到了同样的问题!

    Xcode 会自动从我的 mlmodel 文件中生成以下代码。 但是“MLModel”没有“loadContentsOfURL ...”。 自动生成的文件不可编辑,我无能为力...

        + (void)loadContentsOfURL:(NSURL *)modelURL configuration:(MLModelConfiguration *)configuration completionHandler:(void (^)(AIASCore * _Nullable model, NSError * _Nullable error))handler {
        [MLModel loadContentsOfURL:modelURL
                     configuration:configuration
                 completionHandler:^(MLModel *model, NSError *error) {
            if (model != nil) {
                AIASCore *typedModel = [[AIASCore alloc] initWithMLModel:model];
                handler(typedModel, nil);
            } else {
                handler(nil, error);
            }
        }];
    }
    

    【讨论】:

    • 同样的问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-27
    • 2017-01-29
    • 2014-03-15
    • 2020-07-24
    • 2016-02-23
    相关资源
    最近更新 更多