Skip to content

Instantly share code, notes, and snippets.

@anupamchugh
Created October 5, 2019 18:11
Show Gist options
  • Save anupamchugh/26586328d03eff59c4e7a63247376626 to your computer and use it in GitHub Desktop.
Save anupamchugh/26586328d03eff59c4e7a63247376626 to your computer and use it in GitHub Desktop.
let modelConfig = MLModelConfiguration()
modelConfig.computeUnits = .cpuAndGPU
let updateTask = try MLUpdateTask(forModelAt: modelURL, trainingData: batchProvider(), configuration: modelConfig,
progressHandlers: MLUpdateProgressHandlers(forEvents: [.trainingBegin,.epochEnd],
progressHandler: { (contextProgress) in
print(contextProgress.event)
}) { (finalContext) in
if finalContext.task.error?.localizedDescription == nil
{
let fileManager = FileManager.default
do {
let documentDirectory = try fileManager.url(for: .documentDirectory, in: .userDomainMask, appropriateFor:nil, create:true)
let fileURL = documentDirectory.appendingPathComponent("CatDog.mlmodelc")
try finalContext.model.write(to: fileURL)
self.updatableModel = self.loadModel(url: fileURL)
} catch(let error) {
print("error is \(error.localizedDescription)")
}
}
})
updateTask.resume()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment