Skip to content

Instantly share code, notes, and snippets.

@DejanEnspyra
Created October 31, 2017 16:10
Show Gist options
  • Save DejanEnspyra/55adb5b5081fd16ef5d9545caf3664dc to your computer and use it in GitHub Desktop.
Save DejanEnspyra/55adb5b5081fd16ef5d9545caf3664dc to your computer and use it in GitHub Desktop.
CoreML Place205-GoogLeNet Example (https://theappspace.com)
func scanImage(image: CIImage){
// Load the ML model through its generated class
guard let model = try? VNCoreMLModel(for: GoogLeNetPlaces().model) else {
fatalError("can't load Places ML model")
}
// Create a Vision request with completion handler
let request = VNCoreMLRequest(model: model) { request, error in
guard let results = request.results as? [VNClassificationObservation] else {
fatalError("unexpected result type from VNCoreMLRequest")
}
for r in results{
let percent = Int(r.confidence * 100)
print("\(r.identifier) \(percent)%")
}
}
// Run the Core ML GoogLeNetPlaces classifier on global dispatch queue
let handler = VNImageRequestHandler(ciImage: image)
DispatchQueue.global(qos: .userInteractive).async {
do {
try handler.perform([request])
} catch {
print(error)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment