Skip to content

Instantly share code, notes, and snippets.

@sonsongithub
Created September 18, 2017 02:41
Show Gist options
  • Select an option

  • Save sonsongithub/a5dfab82414c44f02ee0e78c0d0dc27c to your computer and use it in GitHub Desktop.

Select an option

Save sonsongithub/a5dfab82414c44f02ee0e78c0d0dc27c to your computer and use it in GitHub Desktop.
How to update Core ML model with a file in Document directory.
do {
// You have to add the file whose name is changed from KerasMNIST.mlmodel to KerasMNIST.bin to app target.
// In order to avoid that Xcode compiles a mlmodel file automatcally.
guard let url = Bundle.main.url(forResource: "KerasMNIST", withExtension: "bin") else { return }
let compiledURL = try MLModel.compileModel(at: url)
print(compiledURL)
let model = try MLModel(contentsOf: compiledURL)
print(model)
} catch {
print(error)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment