-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgpuCodegenYOLOv8.m
32 lines (25 loc) · 950 Bytes
/
gpuCodegenYOLOv8.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
% Read test image.
I = imread(fullfile('data','inputTeam.jpg'));
% Get classnames of COCO dataset.
classNames = helper.getCOCOClassNames;
numClasses = size(classNames,1);
% Replace 'yolov8n' with other supported models in yolov8Predict to generate code for
% other YOLO v8 variants.
modelName = 'yolov8n';
% Display yolov8Predict function.
type('yolov8Predict.m');
% Generate CUDA Mex.
cfg = coder.gpuConfig('mex');
cfg.TargetLang = 'C++';
cfg.DeepLearningConfig = coder.DeepLearningConfig('cudnn');
inputArgs = {I,coder.Constant(numClasses)};
codegen -config cfg yolov8Predict -args inputArgs -report
% Perform detection using pretrained model.
[bboxes,scores,labelIds] = yolov8Predict_mex(I,numClasses);
% Map labelIds back to labels.
labels = classNames(labelIds);
% Visualize detection results.
annotations = string(labels) + ": " + string(scores);
Iout = insertObjectAnnotation(I, 'rectangle', bboxes, annotations);
figure
imshow(Iout);