Error encountered while Generating PIL Executable for STM32 Nucleo Board
30 views (last 30 days)
Show older comments
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
Answers (1)
Aravind
ongeveer 8 uur ago
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!
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!