AN 1011: TinyML Applications in Altera FPGAs Using LiteRT for Microcontrollers
ID
848984
Date
9/29/2025
Public
1. Overview
2. Preparing LiteRT Inference Model
3. Generating Nios® V Processor System
4. Generating Arm Processor System
5. Programming and Running
6. Nios® V Processor with TinyML Design Example
7. Appendix
8. Document Revision History for the AN 1011: TinyML Applications in Altera FPGAs Using LiteRT for Microcontrollers
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_