Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.