Yolov3 CUDA code generation for NVIDIA Jetson using GPU Coder throws Class 'coder.dlnetwork' does not have a method or property with name 'detect'

5 views (last 30 days)
Sehairi K.
Sehairi K. on 18 Apr 2022
Answered: Sayan Saha on 12 May 2022
Hi all,
As mentioned on the title I am trying to generate CUDA code from a trained YOLO_v3 neural network.
I saved my network using
net = persondetector.yolov3Detector.Network
matFile = 'YOLOv3Detector12K.mat';
This the function I have used:
function detectpedestrian5()
persistent mynet
hwobj = jetson;
w = camera(hwobj,"vi-output, imx219 7-0010",[1280 720]);
d = imageDisplay(hwobj);
if isempty(mynet)
mynet = coder.loadDeepLearningNetwork('YOLOv3Detector12K_2.mat');
while true
img = snapshot(w);
img = imresize(img,[608 608]);
%[bboxes,scores,labels] = detect(mynet,img,'Threshold',0.6);
[bboxes,scores,labels] = mynet.detect(img,'Threshold',0.6);
[~,idx] = max(scores);
% Annotate detections in the image.
if ~isempty(bboxes)
outImg = insertObjectAnnotation(img,'Rectangle',bboxes(idx,:),labels);
outImg = img;
This is the configuration I have used:
cfg = coder.gpuConfig('exe');
cfg.Hardware = coder.hardware('NVIDIA Jetson');
cfg.Hardware.BuildDir = '~/Desktop/GPUcodeGeneration/test9';
cfg.GenerateExampleMain = 'GenerateCodeAndCompile'
cfg.DeepLearningConfig = coder.DeepLearningConfig('tensorrt');
cfg.DeepLearningConfig.DataType = 'fp32';
For code generation, I used
codegen('-config ', cfg,' detectpedestrian5', '-report');
When executing this code I get this error
??? Class 'coder.dlnetwork' does not have a method or property with name
Can someone help me resolve this error, or the yolov3 is not supported for GPU generation?
Thanks in advance

Answers (1)

Sayan Saha
Sayan Saha on 12 May 2022
The error thrown is correct. dlnetwork has no method "detect" defined on it. "detect" methods are only defined on object detector objects. To generate code for yolov3 you can load the MATFile with "coder.loadDeepLearningNetwork" as you are doing now and use the loaded "yolov3ObjectDetector" object directly to peform detections. Below is a code snippet for reference:
persistent mynet;
if isempty(mynet)
mynet = coder.loadDeepLearningNetwork('yolov3Detector.mat'); % load the detector itself
There is no need to extract the network stored in the detector and use it. You can certainly do so but you will only be able to invoke predict method on the network in that case.
I am assuming you followed the steps in https://www.mathworks.com/help/gpucoder/ug/yolov3-object-detection-using-gpucoder.html which asks to save the network in a MATFile. I'll reach out to our documentation team to correct it. Thank you for reporting this issue.




Community Treasure Hunt

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

Start Hunting!

Translated by