Last active
September 12, 2017 16:55
-
-
Save francoismarceau29/46367eb0f6d55313f7b6217d9989319a to your computer and use it in GitHub Desktop.
Doing prediction with CoreML
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
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