Skip to content

Instantly share code, notes, and snippets.

@francoismarceau29
Last active September 12, 2017 16:55
Show Gist options
  • Save francoismarceau29/46367eb0f6d55313f7b6217d9989319a to your computer and use it in GitHub Desktop.
Save francoismarceau29/46367eb0f6d55313f7b6217d9989319a to your computer and use it in GitHub Desktop.
Doing prediction with CoreML
func predict(image: UIImage) -> Species? {
do {
if let resizedImage = resize(image: image, newSize: trainedImageSize), let pixelBuffer = resizedImage.toCVPixelBuffer() {
let model = DogAndCatCNN()
let prediction = try model.prediction(data: pixelBuffer)
if prediction.species[0].intValue == 1 {
return .Dog
} else {
return .Cat
}
}
} catch {
print("Error while doing predictions: \(error)")
}
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment