AN 1011: TinyML Applications in Altera FPGAs Using LiteRT for Microcontrollers

ID 848984
Date 4/07/2025
Public

Visible to Intel only — GUID: xly1740470388188

Ixiasoft

Document Table of Contents

2.5.3. Preparing Supporting Header File for LiteRT C Array

The example main() function implements the supporting model_settings.h header file to decode the output of the LiteRT model.

Content of model_settings.h

#ifndef IMAGE_CLASSIFICATION_MODEL_SETTINGS_H_
#define IMAGE_CLASSIFICATION_MODEL_SETTINGS_H_

// Keeping these as constant expressions allow us to allocate fixed-sized arrays
// on the stack for our working memory.

// All of these values are derived from the values used during model training,
// if you change your model you'll need to update these constants.
constexpr int kNumCols = 28;
constexpr int kNumRows = 28;
constexpr int kNumChannels = 1;

constexpr int kMaxImageSize = kNumCols * kNumRows * kNumChannels;

constexpr int kCategoryCount = 10;
constexpr int k0Index	= 0;
constexpr int k1Index	= 1;
constexpr int k2Index	= 2;
constexpr int k3Index	= 3;
constexpr int k4Index	= 4;
constexpr int k5Index	= 5;
constexpr int k6Index	= 6;
constexpr int k7Index	= 7;
constexpr int k8Index	= 8;
constexpr int k9Index	= 9;

constexpr const char* kCategoryLabels[kCategoryCount] = {
  "number 0",
  "number 1",
  "number 2",
  "number 3",
  "number 4",
  "number 5",
  "number 6",
  "number 7",
  "number 8",
  "number 9"
};

#endif  // IMAGE_CLASSIFICATION_MODEL_SETTINGS_H_