Visibility flag on Keypoint Detector Object

41 views (last 30 days)
Marc
Marc on 15 Sep 2025
Commented: Marc on 1 Feb 2026 at 1:59
Hello everyone,
I was wondering if anyone could help me understanding how to set up the training data for KeyPoint Detector Object (trainHRNETObjectKeypointDetector).
The help says:
"Keypoint locations, defined in spatial coordinates as an N-by-2 or N-by-3 numeric matrix with rows of the form [x y] or [x y v], respectively, where:
  • N is the number of keypoint classes.
  • x and y specify the spatial coordinates of a keypoint.
  • v specifies the visibility of a keypoint."
I was wondering how to setup the visibility flag v .
Is it 1 when the key point is visible and annotated and 0 when it is not. Or same as Yolo 0 = key point out of view and not labelled; 1 = key point present but not visible; 2 = key point visible ?
Thank you very much for your help

Answers (1)

Vivek Akkala
Vivek Akkala on 18 Sep 2025
As mentioned in the doc, A value of 1 (true) indicates a valid keypoint and 0 (false) indicates an invalid keypoint.
  7 Comments
Vivek Akkala
Vivek Akkala on 28 Jan 2026 at 18:06
Thanks for the clarification, @Andreas. You can include images where not all keypoints are visible. In such cases, you can assign a very small value (e.g., 1e‑5 or 1e‑4) to the non‑visible keypoints. Ideally, setting them to 0 should work, but it appears that trainHRNetObjectKeypointDetector is not configured to accept zeros. Using a small non‑zero value for missing keypoints should help avoid error mentioned by Marc.
Marc
Marc ungefär 14 timmar ago
I have been indeed to find workarounds and have trained my model. This has however been quite a trial-error process for me and here are a few of my obsersations:
1- The 2 main files that were responsible of my issues were: hrnetObjectKeypointDetector.m and trainHRNetObjectKeypointDetector.m, both in the folder matlabroot\...\toolbox\vision\vision
the function hrnetObjectKeypointDetector is called around line 100 in trainHRNetObjectKeypointDetector as the minibatchfcn argument
2- In the trainHRNetObjectKeypointDetector, under the iValidateData function, you can see that the verification below is made on the keypoints including a potential third visibility column (data{2}, being the keypoints table in your datastore)
validateattributes(data{2}{:,:}{:},{'numeric'},{'finite','real','nonzero','positive'})
This means that:
a. If the third column in your keypoint table is a visibility flag, with a 0/1 value, it will trigger an error message
b. If some keypoints are missing in a given frame, they still need to have a valid set of coordinates. A NaN, negative or [0 0] set of coordinates will also trigger an error.
A [1 1] set of coordinates (or upper left corner of your bounding box if using one) could work. However, this can be problematic when training the model. If there is a repetitive and characteristic enough pattern in upper left corner of your camera field of view/bounding box, this will most likely been seen as a valid feature and could greatly impact the quality of the detection.
Otherwise, but not sure it is authorised, another option could be to modify the iValidateData function, commenting that line, and save the trainHRNetObjectKeypointDetector file as a custom function in your own CD. You would however need to be 100% certain that your datastore is completely correct (still no NaN or 0 values), but this would at least allow you to pass a 0/1 flag column to the minibatch function
3- In the hrnetObjectKeypointDetector file, under the preprocessHRNetForTraining function, you can see that a heatmat is generated for every points, regardless of whether or not there is a visibility column. This means that even the points with dummy coordinates are being processed, which as stated above, could lead to training errors. I haven't done a complete test of it, but it should be possible here to modify this part of the function (again if authorised) by reading the flag value and replacing the dummy coordinates by NaN values.
So in summary, if this doesn't have any side effect for training your model, the easiest way, but somehow a still bit uncomfortable, is to allocate dummy but real coordinates to the non-visible keypoints as the visibility column is not taken into account and could trigger errors. If allocating dummy coordinates isn't a solution for you, the only option remaining is to have a visibility column and modify the 2 functions as describe above.
One more time, my apologies is some of these suggestions are not permitted by copiright rules and fingers crossed this will be address in a future release. Otherwise hope my observations are accurate and this helps you

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!