-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgpuCodegenYOLOv8Seg.m
31 lines (24 loc) · 986 Bytes
/
gpuCodegenYOLOv8Seg.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
% 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 'yolov8SegPredict.m' to
% generate code for other YOLO v8 variants
modelName = 'yolov8m';
% Display yolov8SegPredict function
type('yolov8SegPredict.m');
% Generate CUDA Mex
cfg = coder.gpuConfig('mex');
cfg.TargetLang = 'C++';
cfg.DeepLearningConfig = coder.DeepLearningConfig('cudnn');
inputArgs = {I,coder.Constant(numClasses)};
codegen -config cfg yolov8SegPredict -args inputArgs -report
% Perform detection using pretrained model
[masks,labelIds, scores, bboxes] = yolov8SegPredict_mex(I,numClasses);
% Map labelIds back to labels
labels = classNames(labelIds);
Idisp = insertObjectAnnotation(I,"rectangle",bboxes,labels);
numMasks = size(masks,3);
overlayedImage = insertObjectMask(Idisp,masks,MaskColor=lines(numMasks));
figure;imshow(overlayedImage);