MLUpdateContext пуст при обновлении модели CoreML - PullRequest
0 голосов
/ 15 апреля 2020

Моя проблема заключается в следующем - В приведенном ниже методе переменная finalContext, похоже, ничего не содержит. Я получаю сообщение об ошибке: Error: The operation couldn’t be completed. (Foundation._GenericObjCError error 0.) при вызове функции. Мне нужна помощь, как отладить эту проблему или что может быть причиной этого. РЕДАКТИРОВАТЬ - finalContext не содержит модель, к которой я пытаюсь получить доступ.

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)")
    }
}

Ответы [ 2 ]

0 голосов
/ 17 апреля 2020

Я нашел проблему здесь. MLArrayBatchProvider не был правильно настроен мной, поэтому задача обновления не была выполнена должным образом.

0 голосов
/ 16 апреля 2020

Es domaj, ka vajag panemt iepist al un paprovet Velreiz

...