How can I avoid "Unsupported custom layer" error during Code Generation using %#codegen pragma in MATLAB R2025a and later?

While generating C code for my MATLAB function or Simulink model which loads and calls my neural network to produce output predictions, I encountered this error:
Unsupported custom layer 'kConcatenate1Layer789'.
Code generation does not support custom layers without '%#codegen' defined in the class definition.
Does this mean the custom concatenate layer is unsupported by MATLAB Coder? How do I fix it?

 Respuesta aceptada

MathWorks Support Team
MathWorks Support Team el 24 de Mzo. de 2026 a las 0:00
Editada: MathWorks Support Team el 24 de Mzo. de 2026 a las 20:36
This is expected. This error indicates that your custom layer "kConcatenate1Layer789" lacks the required "%#codegen" pragma in its class definition. The custom layer class must be explicitly marked for code generation as described in this MathWorks documentation for defining custom layers for code generation.
Add the pragma like this:
classdef kConcatenate1Layer789 < nnet.layer.Layer %#codegen
...
end
We also suggest running the following code to verify full compatibility of your network with C code generation. This can flag layers and syntax which is not supported for code generation:
analyzeNetworkForCodegen('<model>.mat')

Más respuestas (0)

Categorías

Más información sobre Deep Learning with GPU Coder en Centro de ayuda y File Exchange.

Productos

Versión

R2025a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by