Code Generation for Vision Model

This section provides step-by-step information on generating, optimizing and validating the code for object detection models trained in DEEPCRAFT™ Studio.

⚠️

The code generation for Object Detection models is only supported on PSOC™ Edge boards.

Prerequisites

Before you begin, set up the following hardware and software requirements:

Hardware:

  • PSOC™ Edge board for deploying the generated code
  • Supported camera
  • Supported display

For detailed information on boards, compatible displays and cameras, refer to this section (opens in a new tab).(Link to CE)

Software:

  • DEEPCRAFT™ Studio 5.6 or later (for training and downloading the trained Object Detection models)
  • Eclipse IDE for ModusToolbox™ 2025.8 or later (recommended this section demonstrates the flow using Eclipse IDE)
  • ModusToolbox™ Tools Package 3.6.0 or later
  • ModusToolbox™ Machine Learning Pack 3.0.0 or later

ModusToolbox™ and ModusToolbox™ Machine Learning Pack can be installed through ModusToolbox™ Setup. Download the setup application from here (opens in a new tab).

Retrieving the trained Object Detection model

The quickest way to retrieve a trained Object Detection model for deployment is through the New Project-wizard in Studio. This is accessed through 'File' > 'New Project...' or through the quick pane under the File menu.

Note: You have the choice to create a ModusToolbox™ project when creating the Studio project. You can do this at this stage or later, but for the purpose of following the flow of this guide, you should do it later.

ℹ️

Creating this project might take a while if you download the additional data. This data allow you to retrain the model from scratch and is not necessary to follow this guide.

Get the model file

The model file is located under the \Models directory in the newly created project. You have to use the '_int8.tflite' version for compatibility with the rest of this guide.

If you retrained this model or another Object Detection from scratch you will have to download the model from your training job to retrieve it. To know how to download the Model file, refer to Download the Model and Model Predictions (opens in a new tab).

Creating Object Detection compatible ModusToolbox™ project

ℹ️

We are using the Eclipse IDE for ModusToolbox™ for explaining the steps.

  1. Open ModusToolbox™ > Eclipse IDE for ModusToolbox™. The Eclipse IDE for ModusToolbox window appears.

  2. Select New Application from the Quick Panel or navigate to File> New> Modus Toolbox™ Application to open the Project Creator Tool.

  3. Expand the PSOC™ Edge BSPs and select the BSPs (Board Support Packages) that matches your hardware and click Next. The Select Application window appears.

  1. In Template Application, expand Machine Learning and select the PSOC Edge Machine Learning DEEPCRAFT Deploy Vision deploy code example and click Create. The project creation might take a while as the required libraries and configuration scripts are downloaded and executed.

  2. After you create the project, open Project Explorer, expand 'proj_cm55' directory, and double‑click design.mtbl file to launch ML Configurator with optimized, compatible code‑generation settings. For some projects, where design.mtbl is missing, select your ModusToolbox project directory, navigate to Quick panel> Library Configurators and click ML Configurator 3.0.

ℹ️

ML Configurator is included with the ModusToolbox™ Machine Learning Pack. If ML Configurator is not installed, see the 'Prerequisites' section

Code Generation

  1. Under the Model window, in the Pretrained model field, click the folder icon to browse and select the model_int8.tflite downloaded earlier.
ℹ️
  • Future versions of the DEEPCRAFT™ Studio will support code generation for the .tflite models. Revisit this section to follow the simplified flow.
  • Launching the ML Configurator by double-clicking the design.mtbl in 'proj_cm55' directory will launch the ML Configurator with optimized, compatible settings for code generation. Refer to Configuring the code generation from scratch to set the parameters in ML configurator if not set already.
  1. In Output folder, click the folder icon to browse and select the ModusToolbox™ project directory to generate the code in the 'proj_cm55/mth_ml_gen' folder.

  2. Click Generate Source to generate the code.

ℹ️

If you get the following error message 'System Config under Vela options is not correctly set', select one of the available 'System configs' in the dropdown under Vela options to enable the 'Generate Source' button.

Optional: Configuring the code generation from scratch

If you want to create a valid code generation configuration from scratch, below are the required settings for Object detection models.

Parameter NameRecommended ValueDescription
Output file prefixYOLOV5NThis prefix name will generate code that can be used directly with the provided code example project
Output foldermtb_ml_genThe folder will allow the generated code to directly replace the existing files and project structure for the provided code example project
Target devicePSOC Edge - Arm Cortex M55 + Ethos U55The provided code example project utilizes the CM55 core
Pretrained model(path)/model_int8.tfliteBrowse to the location of the .tflite model from the DEEPCRAFT Studio model directory or location of downloaded model file
Imported tflite model quantizationint8x8Selection to align with model quantization
TypeClassificationThis object detection model is a classification type model
System configPSE8x_U55_400Mhz_SOCMEM_200Mhz_QUAD_XIP or PSE8x_U55_400Mhz_SOCMEM_300Mhz_QUAD_XIP-
Dataset structureRandom-
Sample count>= 10Recommended to reduce this value to less than 10. A very low value might cause issues during validation
Arena cache size>= 4000000Recommended to increase this value to greater than 1000000

After you have generated the code, refer to the Deploy Vision Model on PSOC™ Edge boards to know the deployment steps.