Deploying YoloV3 to Jetson Nano

9 views (last 30 days)
function outImg = YoloOnJetson(cameraName,resolution)
% Copyright 2021-2022 The MathWorks, Inc.
hwobj = jetson;
camObj = camera(hwobj,cameraName,resolution);
dispObj = imageDisplay(hwobj);
configFilePath = "E:\JetsonWork\George Camer Object Detection\ssd_mobilenet_v2_coco.config";
persistent yolov3Obj;
if isempty(yolov3Obj)
yolov3Obj = coder.loadDeepLearningNetwork('darknet53-coco.mat');
end
% Read the contents of the configuration file as text
fid = fopen(configFilePath, 'r');
configText = fscanf(fid, '%c', inf);
fclose(fid);
% Load the pre-trained YOLOv3 object detector
detector = yolov3ObjectDetector('darknet53-coco');
while ishandle(1)
% Capture the image from the camera on hardware.
img = snapshot(camObj);
% Detect objects in the frame
[bboxes, scores, labels] = yolov3Obj.detect(detector, img);
% Annotate the image with bounding boxes and labels
img = insertObjectAnnotation(img, 'rectangle', bboxes, cellstr(labels));
% Display the annotated image
% Display the annotated image
image(dispObj,img);
end
I am trying to run this code in order to generate an .exe of this code to my Jetson Nano Developer Kit
>> inputArgs = {coder.Constant(camName),coder.Constant(camResolution)};
codegen('-config ',cfg,'-args',inputArgs,'YoloOnJetson','-report');
The 'yolov3ObjectDetector' class does not support code generation.
Error in ==> YoloOnJetson Line: 20 Column: 12
Code generation failed: View Error Report
Error using codegen
I usually get this error, I do have the darknet53-coco.mat file in my file directory, I did generate it somehow playing around.
It's werid because yolov3ObjectDetector shall be compatible with code generation, what can I do?

Accepted Answer

Ahmed Tamer
Ahmed Tamer on 24 Nov 2023
Fixed, thanks.

More Answers (1)

Walter Roberson
Walter Roberson on 22 Nov 2023
if isempty(yolov3Obj)
yolov3Obj = coder.loadDeepLearningNetwork('darknet53-coco.mat');
end
That step looks good: you are loading a pre-trained detector that should be of the right class.
detector = yolov3ObjectDetector('darknet53-coco');
But there you are trying to create a new object of that class. Creating a new object of the class is not supported in deployed code: all you can do in deployed code is load an already-trained detector and use the detect() method of that pre-trained detector.
  1 Comment
Ahmed Tamer
Ahmed Tamer on 22 Nov 2023
I do believe that
detector = yolov3ObjectDetector('darknet53-coco');
Is a part to identify the detector variable in my code, because if you go down
% Detect objects in the frame
[bboxes, scores, labels] = yolov3Obj.detect(detector, img);
You can see that It is used here, so once I comment the command that you highlighted, I do get this error
codegen('-config ',cfg,'-args',inputArgs,'YoloOnJetson','-report');
Undefined function or variable 'detector'.
Error in ==> YoloOnJetson Line: 27 Column: 49
Code generation failed: View Error Report

Sign in to comment.

Categories

Find more on Computer Vision Toolbox 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!