How to generate code for a Deep Learning network imported from PyTorch?
Afficher commentaires plus anciens
I have imported a model into MATLAB using "importNetworkFromPyTorch". The network works in MATLAB and I try to generate code using the following documentation example: Generate Generic C/C++ Code for Deep Learning Networks
However, I receive errors such as:
Unsupported custom layer 'aten__linear0'. Code generation does not support custom layers without '%#codegen' defined in the class definition.
The 'nnet.layer.AutogeneratedFromPyTorch' class does not support code generation.
Why am I getting this error, and how can I fix it?
Réponse acceptée
Plus de réponses (1)
Bill Chou
le 7 Juil 2026 à 14:12
0 votes
If you continue to encounter errors generating code from dlnetwork objects imported from PyTorch or TensorFlow models, starting in R2026a, you can use the new MATLAB Coder Support Package for PyTorch and LiteRT Models to generate C/C++/CUDA code directly from PyTorch and LiteRT models.
The generated code is readable and portable C/C++/CUDA source code. The support package has been tested on a variety of pretrained deep learning networks including Whisper, DINOv2, Depth Anything, SAM2, and YOLOv11. The generated code includes the complete AI application including any pre- and post-processing MATLAB code and Simulink blocks along with the trained AI models. You can also optionally optimize the generated code with SIMD, OpenMP, and processor-specific intrinsics for target hardware (e.g., ARM Cortex-A/M, x86 architectures).
See the following page for more details:
Catégories
En savoir plus sur Deep Learning with GPU Coder dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!