Last active
May 23, 2018 09:46
-
-
Save codePrincess/8839daacc0c55f78220c75248d308862 to your computer and use it in GitHub Desktop.
Validate the result of a CoreML request
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
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