![](/img/trans.png)
[英]ios / CoreML - The input type is MultiArray when keras model is converted to CoreML
[英]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.