How to compute inference time (ms) to compare my Original, Projected and Fine Tuned models? Error For code generation of convolution1dLayer, when convolving over the time dime
Show older comments
I am trying to compute the inference time of three different models (Original, Projected, and Fine-Tuned) to compare their performances not only with my evaluation metrics and in terms of dimensions (number of learnable parameters) but also in terms of inference time. I am following this example: https://it.mathworks.com/help/deeplearning/ug/compress-network-for-estimating-soc.html. The architectures of my networks are as follows:
Original Net:
- 'input' Sequence Input Sequence input with 1 dimensions
- 'conv1' 1-D Convolution 10 8×1 convolutions with stride 1 and padding 'same'
- 'batchnorm1' Batch Normalization Batch normalization with 10 channels
- 'relu1' ReLU ReLU
- 'gru1' GRU GRU with 32 hidden units
- 'output' Fully Connected 1 fully connected layer
Projected and Fine Tuned Net:
- 'input' Sequence Input Sequence input with 1 dimensions
- 'conv1' 1-D Convolution 10 8×1 convolutions with stride 1 and padding 'same'
- 'batchnorm1' Batch Normalization Batch normalization with 10 channels
- 'relu1' ReLU ReLU
- 'gru1' Projected Layer Projected GRU with 32 hidden units
- 'output' Projected Layer Projected fully connected layer with output size 1
This is my code:
cfg = coder.config("mex");
cfg.TargetLang = "C++";
cfg.DeepLearningConfig = coder.DeepLearningConfig("none");
noisyInputType = coder.typeof('double', [Inf 1], [1 0]);
codegen -config cfg FinalFineTuned_predict -args {noisyInputType}
codegen -config cfg FinalProjected_predict -args {noisyInputType}
codegen -config cfg FinalOriginal_predict -args {noisyInputType}
Where the functions are:
function out = FinalOriginal_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('1DCNN_LSTM07.mat');
end
outDlarray = predict(mynet, dlarray(single(in), 'TCB'));
out = extractdata(outDlarray);
end
2nd function:
function out = FinalProjected_predict(in) %#codegen
persistent mynet;
if isempty(mynet)
mynet = coder.loadDeepLearningNetwork('FinalProjected_unpacked.mat');
end
outDlarray = predict(mynet, dlarray(single(in), 'TCB'));
out = extractdata(outDlarray);
end
3rd function:
function out = FinalFineTuned_predict(in) %#codegen
persistent mynet;
if isempty(mynet)
mynet = coder.loadDeepLearningNetwork('FinalFineTuned_unpacked.mat');
end
outDlarray = predict(mynet, dlarray(single(in), 'TCB'));
out = extractdata(outDlarray);
end
I had to unpacked the projected layers in both the Projected and Fine Tuned networks, otherwise I had an error while compiling.
In all the cases, the error I am encountering now is: "For code generation of convolution1dLayer, when convolving over the time dimension ('T'), the 'T' dimension of the input must be fixed size." Can you help me?
Thank you in advance,
Silvia
Accepted Answer
More Answers (0)
Categories
Find more on Deep Learning Code Generation Fundamentals in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!