Error encountered while Generating PIL Executable for STM32 Nucleo Board
64 views (last 30 days)
Show older comments
Silvia
on 21 Nov 2024 at 10:15
Commented: Katja Mogalle
on 4 Dec 2024 at 14:44
Hello,
I implemented the following code:
clc;
clear;
close all;
% Reference example: example: https://it.mathworks.com/help/coder/ug/generate-code-for-lstm-network-and-deploy-on-cortex-m.html
%% Load Network
load RNN_08Nov_FT.mat
load RNN_08Nov_FT_Unproj.mat
%% Load Test Set
folder = "***";
dataDir = string(folder + "\dataset");
% Prepare DataStore object to consume data
ds_Test = signalDatastore(fullfile(dataDir,"test3"), ...
SignalVariableNames=["noisySignal","cleanSignal"], ...
ReadOutputOrientation="row");
% Take the first test set sample
firstdata = read(ds_Test);
noisyInput = firstdata{1};
cleanTarget = firstdata{2};
%% Generic C code generation
% Create a Code Configuration Object
cfg = coder.config('lib','ecoder',true);
% Configure Object for PIL (processor-in-the-loop) Execution
cfg.VerificationMode = 'PIL';
% Specify 'None' as the TargetLibrary when creating a DeepLearningConfig to
% specify no third-parties deep learning libraries (Generate plain C):
cfg.DeepLearningConfig = coder.DeepLearningConfig('TargetLibrary', 'none');
% Specify Target Hardware
cfg.Hardware = coder.hardware('STM32 Nucleo F401RE');
% Set PIL Communication Interfance (a serial PIL communication interface)
cfg.Hardware.PILInterface = 'Serial';
% Determine the COM port for serial communication
cfg.Hardware.PILCOMPort = 'COM5';
% Limit stack size because the default stack size is much larger than the
% available memory on the hardware. Set to a smaller value (try with 512)
cfg.StackUsageMax = 512;
% View the log
cfg.Verbose = 1;
% Specify the Code Replacement Library for Cortex-M
cfg.CodeReplacementLibrary = 'ARM Cortex-M (CMSIS)';
%% Generate PIL Executable that accepts a single observation of variable sequence length
% Type function loads the network (in .mat file) into a persistent variable
% The function reuses this persistent object on subsequent prediction calls
type rnnFineTuned_predict.m % Fine-tuned prediction function for RNN
% Specify input type and size of the input argument tp the codegen command
% by using the coder.typeof function
noisyInputType = coder.typeof(double(0), [10000 1], [false false]);
% Generate PIL Executable
codegen -config cfg rnnFineTuned_predict -args {noisyInputType} -report
I encountered this error:
"### Generating compilation report ...
An error occurred while calling the SIL or PIL target connectivity implementation.
Error(s) encountered while building "rnnFineTuned_predict""
Searching on MATLAB Answers I saw that there's a way to analyze better the error, running "dbstop if all error" and then running again the model to see if MATLAB stops at the point that the error occurs. And what I receive is:
"### Compiling function(s) rnnFineTuned_predict ...
Caught-error breakpoint was hit in GRUProjectedLayer>iCheckFactorDimensions at line 839. The error was:
Error using coder.internal.cliapi.GuardedProject/compile
Value must be scalar or 1-by-3 row vector"
Can you please help me to analyze this error message?
Thank you in advance,
Silvia
0 Comments
Accepted Answer
Aravind
on 25 Nov 2024 at 10:50
It seems you are attempting to deploy an RNN-based model onto an STM32 Nucleo board and are encountering an error during the code generation process.
From the logs you shared, it appears the issue arises from the "rnnFineTuned_predict.m" file you are trying to compile. The error seems to be related to some parameter in the "GRUProjectedLayer" having invalid dimensions.
According to the documentation for the "GRUProjectedLayer" here, parameters such as "InputWeightsLearnRateFactor" and "RecurrentWeightsLearnRateFactor" must be either a scalar or a 1-by-3 vector. Since the error mentions the need for a scalar or a 1-by-3 row vector, it is likely that some of these parameters is assigned a value with incorrect dimensions.
If you have used the "GRUProjectedLayer" in the "rnnFineTuned_predict.m" file, ensure that all parameters have the correct dimensions. If you have not used the "GRUProjectedLayer" directly, it might be included indirectly as part of some deep learning networks, like LSTMs. In this case, review the "rnnFineTuned_predict.m" file to ensure all parameters for functions and objects have values with the correct dimensions, as specified in the official documentation. This should help resolve the error related to incorrect dimensions.
I hope this helps!
2 Comments
Katja Mogalle
on 4 Dec 2024 at 14:44
As Aravind suggested, it sounds like your function rnnFineTuned_predict.m is setting an incorrect value on one of the properties of the GRUProjectedLayer object. Can you check if the error also occurs when executing rnnFineTuned_predict directly (instead of generating code).
If this still doesn't help to resolve the issue, please share your function rnnFineTuned_predict.m including the network so that the community can better help you.
You can also reach out to the MathWorks technical support team: https://uk.mathworks.com/support/contact_us.html
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!