Create a handsome guy classifier with CreateML. Easy mobile deep learning.

CreateML for easy deep learning

Let’s collect data

Training data

Launch CreateML

Train image classification model with CreatML

Use model in iOS mobile app

Get mlmodel

Use models with the Vision framework

func setupVision() -> NSError? {
// Setup Vision parts
let error: NSError! = nil

guard let modelURL = Bundle.main.url(forResource: "ikemenclasifier 1", withExtension: "mlmodelc") else {
return NSError(domain: "VisionObjectRecognitionViewController", code: -1, userInfo: [NSLocalizedDescriptionKey: "Model file is missing"])
}
do {
let visionModel = try VNCoreMLModel(for: MLModel(contentsOf: modelURL))
let objectRecognition = VNCoreMLRequest(model: visionModel, completionHandler: { (request, error) in
DispatchQueue.main.async(execute: {
// perform all the UI updates on the main queue
if let results = request.results {
self.mlCompletion(results)
}
})
})
self.mlRequest = [objectRecognition]
} catch let error as NSError {
print("Model loading went wrong: \(error)")
}
return error
}
let imageRequestHandler = VNImageRequestHandler(ciImage: image, orientation: exifOrientation, options: [:])
do {
try imageRequestHandler.perform(self.mlRequest)
} catch {
print(error)
}
func mlCompletion(_ results: [Any])  {
guard let observation = results.first as? VNClassificationObservation else {
print("its not ml observation")
return
}
print(observation.identifier,observation.confidence)
if observation.identifier == "ikemen" {
resultLabel.text = "イケメン\n\(floor(observation.confidence * 100))"
ikemenCount += 1
} else {
resultLabel.text = "イケメンではない\n\(floor(observation.confidence * 100))"
}
}

Click here for the actual app

Freelance iOS developer. You can ask me for a job from any country. rockyshikoku@gmail.com https://github.com/john-rocky https://twitter.com/JackdeS11