簡體   English   中英

更新 CoreML model 時 MLUpdateContext 為空

[英]MLUpdateContext is empty when updating CoreML model

我的問題如下 - 在變量finalContext下面的方法中似乎不包含任何內容。 我收到錯誤消息: Error: The operation couldn't be completed. (Foundation._GenericObjCError error 0.) Error: The operation couldn't be completed. (Foundation._GenericObjCError error 0.)調用 function 時。 我需要幫助如何調試此問題或可能導致此問題的原因。 編輯 - finalContext不包含我試圖訪問的 model 。

func updateModel(){
    //Configuration for when update is performed
    let modelConfig = MLModelConfiguration()
    modelConfig.computeUnits = .cpuAndGPU
    let fileManager = FileManager.default
    //Image batch for updating the model
    //Might need to change from a batch to a single image
    let updateImages: [UIImage] = [theImage!]
    let imageBatch = createTrainingData(imageArray: updateImages, outputLabel: "dog") // temp outputLabel
    do {
        let updateTask = try MLUpdateTask(forModelAt: globalCompiledModel!, trainingData: imageBatch, configuration: modelConfig,
                         progressHandlers: MLUpdateProgressHandlers(forEvents: [.trainingBegin,.epochEnd],
                          progressHandler: { (contextProgress) in
                            print(contextProgress.event)
                            // you can check the progress here, after each epoch
                         }) { (finalContext) in
                                do {
                                    // Save the updated model to temporary filename.
                                    let documentDirectory = try fileManager.url(for: .documentDirectory, in: .userDomainMask, appropriateFor:nil, create:true)
                                    let fileURL = documentDirectory.appendingPathComponent("CatDog.mlmodelc")
                                    print("Updated temp model URL: \(fileURL)")
                                    try finalContext.model.write(to: fileURL)
                                } catch(let error) {
                                    print("Error: \(error.localizedDescription)")
                                }
        })
        updateTask.resume()
    } catch {
        print("Error while updating: \(error.localizedDescription)")
    }
}

我在這里找到了問題。 我沒有正確配置 MLArrayBatchProvider,因此 updateTask 沒有正確完成。

Es domaj, ka vajag panemt iepist al un paprovet velreiz

對我來說,通過放棄使用符合 id<MLFeatureProvider> 的 UpdatableTrainingInput class 解決了這個問題,而是創建了一個 MLDictionaryFeatureProvider,如下所示: https://developer.apple.com/documentalupdates_personizing? =對象

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM