Performing inference 

This may come as a bit of an anticlimax for someone expecting some hardcore coding, but its simplicity definitely pays tribute to the effort of Apple's engineers in making this framework one of the most accessible ways to work with a ML model. Without further ado, let's put the final pieces together; we start by instantiating an instance of our model we had imported in the previous section.

Near the top, but within the body of the ViewController class, add the following line:

let model = Inceptionv3()

Our model is now ready; we return to the onFrameCaptured method, starting from where we previously left off, and add the following code snippet:

let prediction = try? self.model.prediction(image:scaledPixelBuffer)

// Update label
DispatchQueue.main.sync {
classifiedLabel.text = prediction?.classLabel ?? "Unknown"
}

In case you have missed it, I have made the statement performing inference in bold. That's it!

After performing inference, we simply assign the classLabel property (the class with the highest probability) to our UILabel, classifiedLabel.

With the final piece put in place, we build and deploy. And see how well our app performs, recognizing some objects we have lying nearby. Once you're done surveying your space, return here, where we will wrap up this chapter and move on to greater and more impressive examples. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.218.157.34