Skip to content

Instantly share code, notes, and snippets.

@codePrincess
Last active May 23, 2018 09:46
Show Gist options
  • Save codePrincess/8839daacc0c55f78220c75248d308862 to your computer and use it in GitHub Desktop.
Save codePrincess/8839daacc0c55f78220c75248d308862 to your computer and use it in GitHub Desktop.
Validate the result of a CoreML request
public func handleClassification(request: VNRequest, error: Error?) {
guard let observations = request.results as? [VNClassificationObservation]
else { fatalError("unexpected result type from VNCoreMLRequest") }
guard let best = observations.first else {
fatalError("classification didn't return any results")
}
DispatchQueue.main.async {
if best.identifier.starts(with: "Unknown") || best.confidence < 0.50 {
print("Mhm, no cat or absolutely not sure about it's mood")
} else {
print("This cat seem to be in a \(best.identifier) mood (\(best.confidence) sure"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment