Last active
October 17, 2020 09:11
-
-
Save SlappyAUS/598283c7cf885c8e8241f3de571c0df9 to your computer and use it in GitHub Desktop.
Image Classification Model #coreml
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
| 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