Skip to Content
DEEPCRAFT™ Studio 5.14 has arrived. Read more →

Code generation and Model Deployment for Ready Models

After you evaluate the Ready Model, generate optimized C code for the target edge device.

How to generate code?

You can generate code in the following ways:

  • Option 1: Graph UX: Includes pre-processing and post-processing.
  • Option 2: Classic UI: Does not include post-processing.
  • Option 3: Quantized model in Graph UX: Includes pre-processing and post-processing.

Option 1. Graph UX (includes pre-processing and post-processing)

To generate code with the post-processor included, follow these steps:

  1. Open the CodeGenGraphUX/Main.imunit Graph UX project in DEEPCRAFT™ Studio.

  2. Click the Generate Source Code button on the top bar, next to the Play button.

  3. Configure the code generation settings:

    • Select your target hardware in the Architecture dropdown.
    • Tick the Enable CMSIS-DSP Hardware Acceleration checkbox.
    • Customize the remaining settings as desired.
  4. Click Ok to generate the code.

ℹ️

The .tflite model included in the Graph UX project is not suited for quantization. To produce quantized code, refer to Option 3.

ℹ️
  • To generate code for a model you trained, delete the preprocessor and model blocks from the Graph UX project. Drag and drop your new model .h5 file onto the canvas — this creates two nodes, a preprocessor and a model. Delete the .h5-based model node, then generate a .tflite version of your model by following Option 3 and drag and drop it onto the canvas as the replacement model block. Connect Data Input as the Input to the preprocessor, connect the preprocessor Output to the model Input, and connect the model Output to the Consecutive Detections Filter node. Then follow the steps above starting from step 2.
  • The Graph UX project can also be used for model evaluation. Refer to Evaluating a classification model using Graph UX to know more.

Option 2: Classic UI (does not include post-processing)

To generate code for the model using the Classic UI, follow these steps:

  1. Open the Ready Model .h5 file in the Model/ folder in DEEPCRAFT™ Studio.

  2. Navigate to the Code Gen tab.

  3. Configure the code generation settings:

    • Select your target hardware in the Architecture dropdown.
    • For preprocessor acceleration: if the option is available for your chosen architecture, select CMSIS Floating Point (Float32). Otherwise, skip this setting.
    • Customize the remaining settings as desired.
  4. Click Generate Code to complete the process.

Option 3. Generating quantized model code in Graph UX (includes pre- and post-processing)

To generate code for a quantized model using Graph UX, follow the steps below in sequence. These steps use Option 2 and Option 1.

  1. Prepare the quantized model using the Option 2 workflow and apply the following settings before generating the code:

    • Tick the Enable Network Quantization checkbox, then:
      • Select NPZ File and choose Model/calibrationData.npz if provided, OR
      • Select Use Project File (.improj) and choose the Ready Model .improj file.
    • Tick the Skip cleanup checkbox.
    • Take note of the location of the generated files:
      • <output_folder>/temp/model_gen_dir/<MODEL_int8x8.tflite>
      • <output_folder>/temp/info/<MODEL_tflm_int8x8_tensor_arena_size.txt>
      • <output_folder>/code_generation_report.md
  2. Set up the Option 1 workflow using the output from the previous step:

    • Remove the model node from the Graph UX canvas, leaving the preprocessor node intact.
    • Drag and drop the <MODEL_int8x8.tflite> file onto the Graph UX canvas.
    • Set the arena size to the recommended value in <MODEL_tflm_int8x8_tensor_arena_size.txt> OR the Scratch Memory (Bytes) value from code_generation_report.md.
    • Connect the preprocessor Output to the model Input.
    • Add a Dequantize node to the graph.
    • Connect the model Output to the Dequantize node.
    • Connect the Dequantize node output to the post-processing Input.
  3. Generate the code as described in Option 1. Select the same target hardware you used in step 1.

If you modify the training dataset, regenerate calibrationData.npz when that file is provided, so quantization reflects the updated data.

Model Deployment

To deploy the generated code on a target device, refer to Model Deployment.

Last updated on