coreMLModel()
Filters an image with a Core ML model.
Declaration
class func coreMLModel() -> any CIFilter & CICoreMLModelReturn Value
The modified image.
Discussion
This method applies the Core ML model filter to an image. The effect filters the image using a trained Core ML model to produce the result. Specifying the head index allows you to produce a result from various components of a multiheaded coreML model.
The Core ML model filter uses the following properties:
inputImageAn image with the type CIImage.
headIndexA
floatrepresenting which output of a multihead Core ML model should be used for applying the effect to an image.softmaxNormalizationA
Booleanvalue representing the softmax normalization to be applied to the output image created by the model.inputModelThe Core ML model to be used for applying effect on the image.
The following code creates a filter that results in the flowers appearing to be glass panes:
func coreML(inputImage: CIImage) -> CIImage {
let coreMLFilter = CIFilter.coreMLModel()
let model = GlassModel().model
coreMLFilter.inputImage = inputImage
coreMLFilter.headIndex = 0
coreMLFilter.softmaxNormalization = false
return coreMLFilter.outputImage!
}[Image]