Deploying YoloV3 to Jetson Nano

5 次查看(过去 30 天)
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?

采纳的回答

Ahmed Tamer
Ahmed Tamer 2023-11-24
Fixed, thanks.

更多回答(1 个)

Walter Roberson
Walter Roberson 2023-11-22
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 个评论
Ahmed Tamer
Ahmed Tamer 2023-11-22
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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Computer Vision Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by