-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathyolov8SegPredict.m
More file actions
31 lines (24 loc) · 827 Bytes
/
yolov8SegPredict.m
File metadata and controls
31 lines (24 loc) · 827 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
27
28
29
30
31
function [masks,labelIds, scores, bboxes] = yolov8SegPredict(image,numClasses)
% Copyright 2025 The MathWorks, Inc.
% Load pretrained network.
persistent net
if isempty(net)
net = coder.loadDeepLearningNetwork('yolov8mSeg.mat');
end
% Get the input size of the network.
inputSize = [640 640 3];
% Apply Preprocessing on the input image.
origSize = size(image);
Ibgr = image(:,:,[3,2,1]);
img = helper.preprocess(Ibgr, inputSize);
newSize = size(img);
img = img(:,:,[3,2,1]);
% Convert to dlarray.
dlInput = dlarray(img, 'SSCB');
% Perform prediction on the input image.
outFeatureMaps = cell(7,1);
[outFeatureMaps{:}] = predict(net, dlInput);
% Apply postprocessing on the output feature maps.
[masks,labelIds, scores, bboxes] = helper.postprocessYOLOv8Seg(outFeatureMaps, ...
origSize, newSize, numClasses);
end