Skip to content

Instantly share code, notes, and snippets.

@SlappyAUS
Last active October 17, 2020 09:11
Show Gist options
  • Save SlappyAUS/598283c7cf885c8e8241f3de571c0df9 to your computer and use it in GitHub Desktop.
Save SlappyAUS/598283c7cf885c8e8241f3de571c0df9 to your computer and use it in GitHub Desktop.
Image Classification Model #coreml
import CoreML
import Vision
func detectImage(image: CIImage) {
guard let model = try? VNCoreMLModel(for: FlowerClassifier().model) else {
fatalError("Could not load CoreML model")
}
let request = VNCoreMLRequest(model: model) { (request, err) in
guard let results = request.results as? [VNClassificationObservation] else {
fatalError("Could not retrieve result")
}
if let firstResult = results.first {
self.navigationItem.title = firstResult.identifier
}
}
let handler = VNImageRequestHandler(ciImage: image)
do {
try handler.perform([request])
} catch {
print("Could not perform the request \(error)")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment