Skip to content

Instantly share code, notes, and snippets.

@digitallysavvy
Created February 29, 2020 04:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save digitallysavvy/41ad7b0f1d19ad85045122246bafc75d to your computer and use it in GitHub Desktop.
Save digitallysavvy/41ad7b0f1d19ad85045122246bafc75d to your computer and use it in GitHub Desktop.
An example snippet of a classification request for my Hotdog NotHotdo project.
func classificationCompleteHandler(request: VNRequest, error: Error?) {
// Catch Errors
if error != nil {
print("Error: " + (error?.localizedDescription)!)
return
}
guard let observations = request.results else {
print("No results")
return
}
// Get Classifications
let classification: VNClassificationObservation = observations.first as! VNClassificationObservation
DispatchQueue.main.async {
// Print Classifications
print("--")
// Display Debug Text on screen
let debugText: String = "- \(classification.identifier) : \(classification.confidence)"
print(debugText)
// Display prediction
var objectName: String = "Not Hotdog"
if classification.confidence > 0.4 {
objectName = "Hotdog"
}
// show the result
self.showResult(objectName)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment