/NutrAI

🤖Artificial intelligence classify a food 🍎 nutritional table by a simple photo. Don't eat 🍔🍕🌮...

Primary LanguageSwift

NutrAI

iOS sample project to demonstrate the use of CoreML Models.

The project uses Food101 CoreMl model to classify the type of food and create tips of meal

The idea is to take a photo of your camera and classify the food, and nutrients of your meal, to provide the best health.

The UIImage is first resized and then converted to a CVPixelBuffer object to can be used by CoreML predict functions.

let attrs = [kCVPixelBufferCGImageCompatibilityKey: kCFBooleanTrue, kCVPixelBufferCGBitmapContextCompatibilityKey: kCFBooleanTrue] as CFDictionary
        var pixelBuffer : CVPixelBuffer?
        let status = CVPixelBufferCreate(kCFAllocatorDefault, Int(newImage.size.width), Int(newImage.size.height), kCVPixelFormatType_32ARGB, attrs, &pixelBuffer)
        guard (status == kCVReturnSuccess) else {
            return (nil, nil)
        }
        
        CVPixelBufferLockBaseAddress(pixelBuffer!, CVPixelBufferLockFlags(rawValue: 0))
        let pixelData = CVPixelBufferGetBaseAddress(pixelBuffer!)

Here you can use the prediction at model.

  guard let prediction = try? model.prediction(image: pixelBuffer) else {
            return
        }

Screen Shot 2019-08-28 at 22 25 25

Screen Shot 2019-08-28 at 22 25 25

Screen Shot 2019-08-28 at 22 25 25

Screen Shot 2019-08-28 at 22 25 25

Screen Shot 2019-08-28 at 22 25 25

Author:

Vinicius Mangueira. Thalys Viana.