Skip to content

Instantly share code, notes, and snippets.

@gali8
Created September 15, 2017 16:14
Show Gist options
  • Save gali8/d939419027b02ec94f7fea7f98066786 to your computer and use it in GitHub Desktop.
Save gali8/d939419027b02ec94f7fea7f98066786 to your computer and use it in GitHub Desktop.
func predictImageVision(image: UIImage) {
let genderModel = try! VNCoreMLModel(for: Gender().model)
let genderRequest = VNCoreMLRequest(model: genderModel) { (req, err) in
guard let results = req.results as? [VNCoreMLFeatureValueObservation], let firstResult = results.first else {
self.resetOnError()
return
}
self.setGender(prob: firstResult.featureValue.multiArrayValue)
}
let handler = VNImageRequestHandler(cgImage: image.cgImage!, options: [:])
try? handler.perform([genderRequest])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment