Article

Integrating Custom Layers

Integrate custom neural network layers into your Core ML app.

Overview

The field of neural networks is constantly evolving, with new architectures and layers rapidly being created to solve new problems. Core ML neural network models can define and use their own custom layers.

Add Third-Party Models with Custom Layers

If you acquire a third-party model that uses custom layers, the Xcode UI for your model will look slightly different than it would for a model with no custom layers. It will show a list of dependencies below the inputs and outputs for the network. The third-party source of your network should provide the implementation of the layer classes to support their network. Add the classes listed in the dependencies to your Xcode project, so that the network can be evaluated properly.

Figure 1

The Xcode view of a custom model, listing the class dependencies of custom layers

In Figure 1 the model has dependencies on the custom layers AAPLAddOneLayer and AAPLSimpleElementwiseLayer. Make sure that the implementations of all dependencies for your model are included in the project to use the model for predictions.

Create Your Own Custom Layer

If no implementation is available for your custom layer, you can create it yourself. Creating a custom layer requires you to be very familiar with the architecture of your neural network and the intended behavior of your custom layer. See Creating a Custom Layer for details.

See Also

Customization

Creating a Custom Layer

Make your own custom layer for Core ML models.

protocol MLCustomLayer

An interface that defines the behavior of a custom layer in your neural network model.

protocol MLCustomModel

An interface that defines the behavior of a custom model.