Error generating MEX PIL due to missing header file for deployment of TFLite model to Raspberry Pi
5 views (last 30 days)
Show older comments
Hi!
I am encountering a problem when I am trying to deploy a TFLite mode for semantic segmentation on Raspberry Pi. I was following this example by following openExample('deeplearning_shared/SemanticSegmentationUsingTFLiteModelOnHostAndRasPiExample')
Before running this example, I have installed the TFLite library on both the local Windows computer directly under "C:\tensorflow-2.15.0" following this link:
and Raspberry Pi 4b (buster; 32bit OS) under "/home/pi/tensorflow/tensorflow/" following this:
Additionally, the environment variables are set on both the local and raspi machines according to:
While I had no problem with generating the MEX file on the local Windows computer with this section of codes in the example:
cfg = coder.config('mex');
cfg.TargetLang = 'C++';
codegen -config cfg tflite_semantic_predict -args ones(257, 257,3,'single')
I encountered errors when I tried to generate the MEX PIL function through
cfg = coder.config('lib','ecoder',true);
cfg.TargetLang = 'C++';
cfg.VerificationMode = 'PIL';
hw = coder.hardware('Raspberry Pi');
cfg.Hardware = hw;
codegen -config cfg tflite_semantic_predict -args ones(257,257,3,'single')
I have attached the entire error message in the txt file. Part of the error message reads:
fatal error: kernels/register.h: No such file or directory
#include "kernels/register.h"
However, when I searched the directories indicated by the environment variables, I could find the kernels/register.h file on both the Windows and RPi machines under the PATH (in Windows) or LD_LIBRARY_PATH (in RPi) variables. Please see the attached screenshots.
Here is how I set the environmental variables. On RPI, I executed:
export TFLITE_PATH="/home/pi/tensorflow/tensorflow"
export LD_LIBRARY_PATH="/home/pi/tensorflow/tensorflow/tensorflow/lite"
export TFLITE_MODEL_PATH="/home/pi"
and on Windows, I directly edited the environmental variable TFLITE_PATH and amended Path variable.
I'd appreciate any advice on how to resolve this missing header file issue by MATLAB coder.
Thank you all!
0 Comments
Accepted Answer
埃博拉酱
on 27 Jan 2025
Environment variables are used to load dynamic libraries at runtime. Your problem now is that the header file is missing at compile time, which has nothing to do with environment variables.
During compilation, you must manually add external include directories provided by your third-party library to the compilation parameters. As for coder.config, you may try to configure the CustomInclude property of the coder.MexCodeConfig object. In addition, it's also a good idea to double-check all the properties listed in that documentation page to make sure you understand what they mean and set them up correctly. Otherwise, you may encounter all sorts of surprises later.
3 Comments
埃博拉酱
on 29 Jan 2025
No. Generally I have no idea.
You can try pausing execution to see if you can find where it gets stuck. You can open the task manager and see if it's still taking up your CPU. You can close MATLAB, restart your computer, and try again.
I'm able to answer this question only because I'm familiar with the C++ compilation process, and the lack of header files is one of the problems I often encounter. However, I haven't actually used MATLAB codegen, so I have very few suggestions. You may need to ask a new question or contact official technical support.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!