How to generate code for a Deep Learning network imported from PyTorch?
이전 댓글 표시
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?
채택된 답변
추가 답변 (1개)
Bill Chou
2026년 7월 7일 14:12
0 개 추천
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:
카테고리
도움말 센터 및 File Exchange에서 Deep Learning with GPU Coder에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!