1D-Convolution Layer not supported by calibrate function

35 views (last 30 days)
Good morning,
I am trying to follow this example: https://it.mathworks.com/help/coder/ug/generate-code-for-quantized-lstm-network-and-deploy-on-cortex-m-target.html on how to generate an Int8 Code for an implementation in a STM32.
My network is composed by the following layers:
6×1 Layer array with layers:
1 'input' Sequence Input Sequence input with 1 dimensions
2 'conv1' 1-D Convolution 10 8×1 convolutions with stride 1 and padding 'same'
3 'batchnorm1' Batch Normalization Batch normalization with 10 channels
4 'relu1' ReLU ReLU
5 'gru1' Projected Layer Projected GRU with 32 hidden units
6 'output' Projected Layer Projected fully connected layer with output size 1
When I try to calibrate the network as described in the example, I have the following error showing that the 1D-convolutional layer is not supported in the CPU environment: "Code generation for conv1 is not supported for target library 'mkldnn'. See documentation for a list of supported layers with each target library."
Can I solve this problem without having to change the 1D-convolutional layer?
Thank you in advance,
Silvia
  5 Comments
Silvia
Silvia on 5 Nov 2024 at 13:27
Thank you @Hariprasad Ravishankar and sorry for the late reply.
I am trying to follow the first possible approach in the example (Generate PIL Executable That Accepts a Single Observation of Variable Sequence Length).
% 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 = 'COM2';
% 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('FinalFineTuned_predict.m')
% Specify input type and size of the input argument tp the codegen command
% by using the coder.typeof function
noisyInputType = coder.newtype('double', [Inf 1], [1 0]);
% Run the codegen command to generate code and PIL executable
codegen -config cfg FinalFineTuned_predict -args {noisyInputType} -report
And my FinalFineTuned_predict.m function is the following:
function out = FinalFineTuned_predict(in) %#codegen
% A persistent object mynet is used to load the series network object.
% At the first call to this function, the persistent object is constructed and
% setup. When the function is called subsequent times, the same object is reused
% to call predict on inputs, thus avoiding reconstructing and reloading the
% network object.
% Copyright 2019-2021 The MathWorks, Inc.
persistent mynet;
if isempty(mynet)
mynet = coder.loadDeepLearningNetwork('FinalFineTuned.mat');
end
% pass in input
out = predict(mynet, in);
When I run the code, I have the following error:
"### Compiling function(s) FinalFineTuned_predict ...
### Generating compilation report ...
Input data argument to predict must be dlarray type.
Error in ==> FinalFineTuned_predict Line: 18 Column: 7
Code generation failed: View Error Report"
To decide the input type, I used the coderTypeEditor giving as input a variable NoisySignal (7716x1 double) and specifying that I don't want to fix the length of the signal (thus [Inf 1] instead of [7716 1]). If I normally use the predict function in a MATLAB script with this NoisySignal (CleanSignal = predict(netFineTuned, NoisySignal)) no errors occur. Do you know what I am missing?
Thank you in advance,
Silvia
Hariprasad Ravishankar
Hariprasad Ravishankar on 5 Nov 2024 at 14:39
For code generation we expect the input to predict to be a dlarray. Please try modifying your function as follows:
function out = FinalFineTuned_predict(in) %#codegen
% A persistent object mynet is used to load the series network object.
% At the first call to this function, the persistent object is constructed and
% setup. When the function is called subsequent times, the same object is reused
% to call predict on inputs, thus avoiding reconstructing and reloading the
% network object.
% Copyright 2019-2021 The MathWorks, Inc.
persistent mynet;
if isempty(mynet)
mynet = coder.loadDeepLearningNetwork('FinalFineTuned.mat');
end
% pass in input
% We first cast the 'double' input to 'single' as code-generation only supports 'single' precision compute for dlnetwork.
% We specify the format of input as 'TC' to indicate that the first
% dimension is 'Time' and second dimension is 'channel'.
outDlarray = predict(mynet, dlarray(single(in), 'TC');
% We extract data from the dlarray to get back the result in 'single'
% datatype.
out = extractdata(outDlarray);
end

Sign in to comment.

Answers (0)

Products


Release

R2024a

Community Treasure Hunt

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

Start Hunting!