Chapter 12. The Hard Way
For our last chapter, we want to take a bit of a step down into the murky world of implementation specifics. Most of this book has used neural networks to do some pretty impressive stuff, but in Chapter 10 and Chapter 11 we discussed the principles underlying machine learning, we haven’t looked at how you make one of these things. How does CoreML actually create a neural network? How would you go about building one yourself from scratch? In this chapter, we peek behind the curtain and build a complete neural network using the same tools and frameworks that Apple uses.
Behind CoreML’s Magic
At the very high level, CoreML works by loading in a pretrained model file, created in a tool such as CreateML or TensorFlow, and then running the model and returning predictions based upon the input you give it.
In “A Look Inside CoreML”, we spoke a bit about how the programmatic internals of CoreML work, but we glossed over the structure of the model format because it isn’t important to understanding how CoreML works.
To understand what CoreML is doing, we do need at least a basic look into the format. The CoreML model format itself is based on the protobuf serialized data format with a custom schema that allows you to define, among other things, the type of machine-learning model, the features of the model, labels, inputs and output, attributes, metadata, and anything else you need to fully describe your model.
At its core the data format precisely describes the ...
Get Practical Artificial Intelligence with Swift now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.