Created
October 31, 2017 16:10
-
-
Save DejanEnspyra/55adb5b5081fd16ef5d9545caf3664dc to your computer and use it in GitHub Desktop.
CoreML Place205-GoogLeNet Example (https://theappspace.com)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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