How can I avoid "Unsupported custom layer" error during Code Generation using %#codegen pragma in MATLAB R2025a?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
MathWorks Support Team
le 28 Août 2025
Réponse apportée : MathWorks Support Team
le 29 Août 2025
While generating C code for my "tf_predict.m" MATLAB function 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?
Réponse acceptée
MathWorks Support Team
le 28 Août 2025
This is expected. This error indicates that your custom layer "kConcatenate1Layer789" lacks the required "%#codegen" pragma in its class definition.
This has nothing to do with the built-in concatenation operation, but rather that 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
Also, I 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')
For more information, please refer to this MathWorks documentation on "analyzeNetworkForCodegen".
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Input Specification dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!