Understanding the basics of Core ML

Core ML enables iOS mobile applications to run machine learning models locally on a mobile device. It enables developers to integrate a broad variety of machine learning model types into a mobile application. Developers do not require extensive knowledge of machine learning or deep learning to write machine learning mobile applications using Core ML. They just need to know how to include the ML model into the mobile app similar to other resources and use invoke it in the mobile application. A data scientist or a machine learning expert can create an ML model in any technology they are familiar with, say Keras, scikit-learn, and so on. Core ML provides tools to convert the ML data model created using other tools (tensor, scikit-learn, and so on) to a format that is mandated by Core ML. 

This conversion to a Core ML model happens during the app development phase. It does not happen in real time when the application is being used. The conversion is done by using the coremltools Python library. When the app deserializes a Core ML model, it becomes an object having a prediction method. Core ML is not really meant for training, just for running pretrained models.

Core ML supports extensive deep learning capabilities with support for more than 30 layers. The layers in deep learning actually suggest the number of layers through which the data is transformed. It also supports standard models: tree ensembles, SVMs, and linear models. It is built on top of low-level technologies such as Metal. Core ML seamlessly takes advantage of the CPU and GPU to provide maximum performance and efficiency. It has the ability to switch between CPU and GPU based on the intensity of the task at hand. Since Core ML lets machine learning run locally on the device, data doesn't need to leave the device to be analyzed.

With Core ML, we can integrate trained machine learning models into our app:

A trained model is the result of applying a machine learning algorithm to a set of training data. The model makes predictions based on new input data. For example, a model that's been trained in a region's historical house prices may be able to predict a house's price when given the number of bedrooms and bathrooms.

Core ML is optimized for on-device performance, which minimizes memory footprint and power consumption. Running strictly on the device ensures the privacy of user data and guarantees that our app remains functional and responsive when a network connection is unavailable.

Core ML is the foundation for domain-specific frameworks and functionality. Core ML supports Vision for image analysis, Foundation for natural language processing, and Gameplaykit for evaluating learned decision trees. Core ML itself builds on top of low-level primitives such as Accelerate and BNNS, as well as Metal Performance Shaders:

An iOS developer who is going to write ML programs using Core ML needs to be aware of the following fundamental steps:

  1. Create the model outside of iOS. This can be done using scikit-learn, TensorFlow, or in any other way with which the developer is comfortable. Create the machine learning model file. For creating the machine learning model file, they need to be aware of the four key phases of machine learning already discussed.
  2. Once the model is built, tested, and ready for use, this model needs to be converted to a format that is compatible with Core ML. Core ML tools are available that actually help to convert the model file created using any tool to a model file that is in a format as mandated by Core ML (.mlmodel file format).
  3. Once the Core ML specific model file is created, the same can be imported into the iOS program and the Core ML-provided APIs can be used to interact with the model file to extract the required information as may be required by the iOS application, basically importing the .mlmodel file into the resources folder of the Xcode project.
Core ML's biggest advantage is that it is extremely simple to use. Just a few lines of code can help to integrate a complete ML model. Core ML can only help to integrate pretrained ML models into an application. No model training is possible.
..................Content has been hidden....................

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