-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathrunInference.m
More file actions
26 lines (20 loc) · 775 Bytes
/
runInference.m
File metadata and controls
26 lines (20 loc) · 775 Bytes
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
% Add path containing the pretrained models.
addpath('models');
% Read test image.
I = imread(fullfile('data','inputTeam.jpg'));
% Get classnames of COCO dataset.
classNames = helper.getCOCOClassNames;
numClasses = size(classNames,1);
modelName = 'yolov8n';
% Load YOLO v8 network with custom split layers.
data = load([modelName,'.mat']);
detector = data.yolov8Net;
% Perform detection using pretrained model.
executionEnvironment = 'auto';
[bboxes, scores, labelIds] = detectYOLOv8(detector, I, numClasses, executionEnvironment);
% 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);