---
title: Creating and Integrating a Model with Custom Layers
framework: coreml
role: article
role_heading: Article
path: coreml/creating-and-integrating-a-model-with-custom-layers
---

# Creating and Integrating a Model with Custom Layers

Add models with custom neural-network layers to your app.

## Overview

Overview New network layers and architectures solve problems that might be difficult or impractical with code. You can support each new layer type before Core ML directly supports it by implementing a custom layer. A custom layer is a class that adopts MLCustomLayer and implements the methods to run a neural network layer in code. note: Core ML supports models with custom layers beginning with these software releases: iOS 11.2, macOS 10.13.2, tvOS 11.2 and watchOS 4.2. Add a model you acquire or create If you have a Core ML model with custom layers, add the model to your Xcode project. Otherwise, convert a third-party model and designate the new layers as custom with the Core ML Tools. Follow the steps on the Custom Operators page to define the new layers as custom. Give each custom layer a unique name by assigning a unique string to the operator’s class name binding. bindings = {     'class_name'  : 'AAPLCustomAdd',     'description' : "Custom implementation of addition."     ... } Save the Core ML model you converted and add it to your Xcode project. Integrate or create a class for each custom layer If the author of the model you plan to add to your Xcode project implemented the custom layers in source-code files, add the source files into your Xcode project. Otherwise, implement each custom layer by creating a Swift or Objective-C class for each layer. Inspect the names of the model’s custom layers by opening the model in Xcode:

Create a class for each custom layer that the model has in its list of dependencies and name each class to match the custom layer it implements. important: Swift classes must subclass NSObject and use the @objc attribute so that Core ML can access your custom layer’s implementation. Adopt the MLCustomLayer protocol by implementing the following: Core ML invokes the appropriate MLCustomLayer methods for each custom layer at runtime when your app calls the prediction(from:) method. warning: Don’t change the values that Core ML provides to these methods — such as weights, inputs, or outputs — because it may cause your app to behave in unexpected ways, and possibly crash. Test the custom layers If applicable, test the custom layers by using the model to make predictions with input values from one or more test cases. Confirm the model layers function correctly by comparing the model’s prediction values to the output values for each test case.

## See Also

### Custom model layers

- [MLCustomLayer](coreml/mlcustomlayer.md)
