loadHRNETObjectKeypointDetector
Description
loads a pretrained HRNet object keypoint detector model net from the MAT file
net
= loadHRNETObjectKeypointDetector(filename
)filename
. filename
must be a compile-time
constant.
Note
This functionality requires Deep Learning Toolbox™ and the Computer Vision Toolbox™ Model for Object Keypoint Detection. You can download and install the Computer Vision Toolbox Model for Object Keypoint Detection from Add-On Explorer. For more information about installing add-ons, see Get and Manage Add-Ons.
Examples
Generate C++ Code from MAT File Containing HRNet Object Keypoint Detector
Use the loadHRNETObjectDetector
function to load
an HRNet object detector and generate C code for the network. You must have a pretrained
hrnetObjectKeypointDetector
object saved as a variable named
detector
in the file
trainedHRNetObjectKeypointDetector.mat
.
Load the pretrained hrnetObjectKeypointDetector
object from the MAT file.
load("trainedHRNetObjectKeypointDetector.mat");
Create an entry-point function myHRNetObject.m
that accepts an
image and the bounding boxes of image objects as input. The entry-point function
performs these operations:
Defines a persistent variable called
myDetector
. The persistent variable prevents reconstructing and reloading the network object during subsequent calls to themyHRNetObject
function.Loads the detector from the file
trainedHRNetObjectKeypointDetector.mat
into themyDetector
variable using theloadHRNETObjectDetector
function.Detects object keypoints, confidence scores, and validity of the objects in the input test image
imTest
using the detector.
function [keypoints,scores,valid] = myHRNetObject(imTest,bboxes) persistent myDetector; if isempty(myDetector) myDetector = loadHRNETObjectKeypointDetector("trainedHRNetObjectKeypointDetector.mat"); end [keypoints,scores,valid] = detect(myDetector,imTest,bboxes); end
Read a test image from a graphics file.
imTest = imread("visionTeam.jpg");
Specify the bounding boxes of objects in the test image.
bboxes = [28.999092 48.454803 136.47928 364.54520; 157.66484 34.789597 101.99452 375.76184; 261.84634 39.663254 123.77393 345.26978; 388.49371 49.597092 111.15561 328.06561; 506.54700 51.744110 140.14929 351.37390; 656.18372 49.514694 134.45197 363.48529];
Create a coder.config
(MATLAB Coder) configuration object for MEX
code generation and set the target language to C++. On the configuration object, set the
DeepLearningConfig
property to the target library
"mkldnn"
, for MKL-DNN targets. For more information about the
supported target libraries for C++ code generation in deep learning networks, see Generate Generic C/C++ Code for Deep Learning Networks (MATLAB Coder).
Note
The HRNet object keypoint detector deep learning network architecture contains
the spaceToDepthLayer
. Code generation for spaceToDepthLayer
is not supported for target library
"none"
.
The codegen
(MATLAB Coder) function must determine the size,
class, and complexity of MATLAB® function inputs. Use the -args
option to specify the
input test image imTest
and object bounding boxes
bboxes
to the entry-point function. Use the
-config
option to pass the code configuration object
myHRNetObject
to codegen
.
cfg = coder.config("mex"); cfg.TargetLang = "C++"; cfg.DeepLearningConfig = coder.DeepLearningConfig(TargetLibrary = "mkldnn"); codegen -args {imTest,bboxes} -config cfg myHRNetObject -report;
The codegen
command places all the generated files in the
codegen
folder. The folder contains the C code for the entry-point
function myHRNetObject.c
, header and source files containing the C
class definitions for the network, weight, and bias files.
Compute the object keypoint locations, keypoint confidence scores, and keypoint
validity in the test image by calling the code-generated MEX file
myHRNetObject_mex
.
[objKeypoints,keypointScores,keypointValid] = myHRNetObject_mex(imTest,bboxes)
objKeypoints(:,:,1) = 80.0250 88.0543 84.5691 83.3077 70.6329 83.3077 93.9612 88.0543 56.8991 92.8010 113.2518 121.2811 48.4184 130.7745 137.5927 173.4946 68.3165 192.4813 95.8852 178.2413 123.7577 178.2413 115.7833 239.9482 69.3291 239.9482 140.9344 330.1351 75.9997 334.8818 151.8454 406.0820 91.4549 406.0820 objKeypoints(:,:,2) = 208.9805 60.3294 218.4503 55.4367 204.0877 55.4367 228.1306 60.3294 194.6179 60.3294 248.2275 104.3640 176.4147 104.3640 253.9619 148.3986 172.6793 153.2913 201.1940 143.5059 234.9171 153.2913 236.0744 207.1114 193.0919 212.0041 237.9681 295.1806 194.9856 300.0733 239.6515 373.4643 191.7762 373.4643 objKeypoints(:,:,3) = 332.8377 58.8094 337.1445 54.3137 323.9408 54.3137 346.1359 63.3051 315.2329 58.8094 360.1899 103.7664 298.3838 94.7750 374.4328 153.2192 282.0071 153.2192 362.1739 198.1762 303.4464 126.2449 353.6549 211.6633 309.5482 207.1676 355.2610 288.0902 298.0451 288.0902 352.1825 351.0300 290.6599 355.5257 objKeypoints(:,:,4) = 449.0307 76.9031 453.1255 72.6314 440.4873 68.3597 461.5805 76.9031 432.2976 76.9031 479.1093 115.3483 416.3604 115.3483 488.5369 166.6085 404.8717 166.6085 489.4212 209.3254 401.5726 209.3254 472.7766 213.5971 426.7607 213.5971 474.1913 281.9441 423.9922 281.9441 471.2460 341.7477 421.1353 346.0194 objKeypoints(:,:,5) = 573.6482 89.4887 582.4121 80.3383 569.0730 84.9135 591.4658 84.9135 560.2125 89.4887 614.7282 126.0901 543.0713 126.0901 633.8019 180.9923 526.2200 176.4171 625.9077 231.3193 522.7077 222.1689 599.1330 235.8945 549.8689 235.8945 600.5824 304.5222 551.2217 299.9470 601.9352 368.5747 552.3812 354.8492 objKeypoints(:,:,6) = 720.0562 83.7954 729.2193 79.0625 715.3233 79.0625 743.3170 88.5283 706.2611 88.5283 762.8539 135.8571 698.0060 135.8571 773.5303 202.1174 680.5878 187.9188 760.7441 254.1791 677.0656 239.9805 742.1152 249.4462 700.3264 244.7133 743.9312 334.6381 706.6735 325.1723 731.5486 405.6313 712.8188 396.1655 keypointScores = 0.9671 0.9648 0.9650 0.9617 0.9565 0.9564 0.9809 0.9810 0.9627 0.9769 0.9846 0.9839 0.9762 0.9953 0.9727 0.9730 0.9699 0.9814 0.9646 0.9943 0.9740 0.9795 0.9659 0.9850 0.9305 0.9845 0.9636 0.9675 0.9577 0.9677 0.9603 0.9220 0.9320 0.9558 0.9397 0.8990 0.9044 0.9620 0.8772 0.9620 0.9502 0.9549 0.9584 0.9620 0.9544 0.9133 0.9080 0.9309 0.9316 0.9707 0.9516 0.9333 0.9222 0.9300 0.7920 0.9553 0.9716 0.9492 0.9421 0.9558 0.9104 0.7432 0.9154 0.9533 0.9711 0.9333 0.8087 0.8730 0.8530 0.8723 0.8607 0.8483 0.7811 0.8598 0.8277 0.8443 0.8671 0.8340 0.8606 0.9081 0.9165 0.9512 0.8997 0.9069 0.8365 0.9004 0.9179 0.9260 0.9611 0.8890 0.8982 0.9391 0.9052 0.9220 0.9360 0.9669 0.7941 0.9696 0.8999 0.9185 0.9210 0.9494 keypointValid = 17×6 logical array 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Input Arguments
filename
— Filename
character vector | string scalar
Filename of the MAT file containing the pretrained HRNet object keypoint detector, specified as a character vector or string scalar. The MAT file must exist on the MATLAB path and contain only the network to be loaded.
This input argument must be a compile-time constant.
Data Types: char
| string
Output Arguments
net
— HRNet object keypoint detector network
hrnetObjectKeypointDetector
object
HRNet object keypoint detector network, returned as a hrnetObjectKeypointDetector
object.
Version History
Introduced in R2023b
See Also
hrnetObjectKeypointDetector
| coder.loadDeepLearningNetwork
(MATLAB Coder) | coder.DeepLearningConfig
(MATLAB Coder)
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)