Error generating MEX PIL due to missing header file for deployment of TFLite model to Raspberry Pi

27 ビュー (過去 30 日間)
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!

採用された回答

埃博拉酱
埃博拉酱 2025 年 1 月 27 日 1:52
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 件のコメント
埃博拉酱
埃博拉酱 2025 年 1 月 29 日 0:22
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.
Peng
Peng 2025 年 1 月 29 日 4:54
編集済み: Peng 2025 年 1 月 29 日 4:56
Thank you for your suggestions and comments. Restarting didn't help. The CPU dropped significantly around 30 seconds after executing the codegen line, while the command window continued showing 'busy' status. When I click 'pause', the pause button grayed out, while command window still showed 'busy' status, which is strange. I had to click the 'stop' button to force the code into the 'pause' status, with the 'continue running. option enabled. I tried this a few times, and every time the code is paused at the 'obj.task();' line inside a delete(obj) function within the onCleanup.m class. Here is the file:
classdef onCleanup < handle
properties(SetAccess = 'immutable', GetAccess = 'public', Transient)
task (1,1) function_handle = @nop;
end
methods
function obj = onCleanup(functionHandle)
arguments
functionHandle (1, 1) function_handle = @nop
end
obj.task = functionHandle;
end
end
methods (Hidden = true)
function obj = saveobj(obj)
persistent haveAlreadyWarned;
if isempty(haveAlreadyWarned)
warning(message('MATLAB:onCleanup:DoNotSave'));
haveAlreadyWarned = true;
end
end
function delete(obj)
obj.task();
end
end
end
function nop
end
%#codegen
% Copyright 2007-2022 The MathWorks, Inc.
I will start a new thread to ask this issue about codegen.

サインインしてコメントする。

その他の回答 (0 件)

製品


リリース

R2024b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by