-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.m
More file actions
54 lines (38 loc) · 1.51 KB
/
test.m
File metadata and controls
54 lines (38 loc) · 1.51 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
% Read the image for inference
%img = imread(img_curr);
img = imread("test1.png");
% Define the target size of the image for inference
targetSize = [700 700 3];
% Resize the image maintaining the aspect ratio and scaling the largest
% dimension to the target size.
imgSize = size(img);
[~, maxDim] = max(imgSize);
resizeSize = [NaN NaN];
resizeSize(maxDim) = targetSize(maxDim);
img = imresize(img, resizeSize);
trainImgSize = [800 800 3];
classNames = {'person', 'car', 'background'};
numClasses = 2;
params = createMaskRCNNConfig(trainImgSize, numClasses, classNames);
% Select execution environment. Can be changed to gpu if the system has a gpu installed.
executionEnvironment = "cpu";
% Downloads the pretrained network
datadir = tempdir;
url = 'https://www.mathworks.com/supportfiles/vision/data/maskrcnn_pretrained_person_car.mat';
helper.downloadTrainedMaskRCNN(url, datadir);
pretrained = load(fullfile(datadir, 'maskrcnn_pretrained_person_car.mat'));
net = pretrained.net;
maskSubnet = helper.extractMaskNetwork(net);
% detect the objects and their masks
[boxes, scores, labels, masks] = detectMaskRCNN(net, maskSubnet, img, params, executionEnvironment);
% Visualize Predictions
% Overlay the detected masks on the image using the insertObjectMask
% function.
if(isempty(masks))
overlayedImage = img;
else
overlayedImage = insertObjectMask(img, masks);
end
figure, imshow(overlayedImage)
% Show the bounding boxes and labels on the objects
showShape("rectangle", gather(boxes), "Label", labels, "LineColor",'g')