Code Generation for Networks
3 ビュー (過去 30 日間)
古いコメントを表示
yazan doha
2022 年 9 月 27 日
コメント済み: Hariprasad Ravishankar
2022 年 9 月 30 日
Hallo everyone,
when we want to generate a Code, we should choose a pretrained net like mobilenetv2() and have an entry-point function for this net, type("mobilenetv2 _predict.m") :
% Copyright 2017-2019 The MathWorks, Inc.
function out = mobilenetv2_predict(in)
persistent mynet;
if isempty(mynet)
mynet = coder.loadDeepLearningNetwork('mobilenetv2','mobilenetv2');
end
% pass in input
out = mynet.predict(in);
My question is: What if I train a standalone network for my project? How can I put it in this function to deploy it on Jetson nano?
Thank you very much
0 件のコメント
採用された回答
Hariprasad Ravishankar
2022 年 9 月 27 日
Hello,
If you have a standlone network, you can save the network to a MAT file and specify the name of the MAT file as the first argument to coder.loadDeepLearningNetwork function as follows.
net = squeezenet; % net could be any custom SeriesNetwork, DAGNetwork or dlnetwork object
save mynet.mat net
function out = mpredict(in)
%#codegen
persistent net;
if isempty(net)
net = coder.loadDeepLearningNetwork('mynet.mat');
end
out = predict(net, in);
end
You can refer to the example link below to deploy your application to NVIDIA Jetson boards:
Here is an example video:
0 件のコメント
その他の回答 (1 件)
yazan doha
2022 年 9 月 28 日
1 件のコメント
Hariprasad Ravishankar
2022 年 9 月 30 日
Hi Yazan,
You can write an entry point function that passes a single input or a batch of inputs to classfiy function. For example:
function out = mclassify(in)
%#codegen
persistent net;
if isempty(net)
net = coder.loadDeepLearningNetwork('mynet.mat');
end
out = classify(net, in);
You can then generate code and interface with it using MEX using GPU Coder as follows:
cfg = coder.gpuConfig('mex');
cfg.DeepLearningConfig = coder.DeepLearningConfig(TargetLibrary = 'cudnn');
codegen -config cfg -args {testInput} mclassify
This will generate a MEX file named mclassify_mex which you can invoke from your test file as follows:
idx2=randi([5,50]);
aug_idx2=augmentedImageDatastore([224 224], idx2);
o2= readimage(imds_test,idx2);
aug_o2=augmentedImageDatastore([224 224], o2);
result2=mclassify_mex(convnet,aug_o2);
Hari
参考
カテゴリ
Help Center および File Exchange で Get Started with GPU Coder についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!