roboflow / supervision

We write your reusable computer vision tools. 💜
https://supervision.roboflow.com
MIT License
18.57k stars 1.44k forks source link

Invalid validations on KeyPoints class? #1440

Closed Chappie74 closed 2 weeks ago

Chappie74 commented 1 month ago

Search before asking

Bug

I'm trying to use the KeyPoints class, with my xy data as [ [x1,y1], [x2,y1], .... ] Based on the information in the docs string this seems to be input needed. However, I run into an error.

ValueError: xy must be a 2D np.ndarray with shape ((68, 2),), but got shape (68, 2)

image

The validation for the shape check does not seems to be consistent. Either that or I may be doing something wrong image

Environment

Supervision: 0.22.0 Python: 3.10

Minimal Reproducible Example

sv.KeyPoints(xy=np.array([[1,3], [1,3], [1,3]]))

Additional

No response

Are you willing to submit a PR?

LinasKo commented 1 month ago

Indeed, the docs are not correct. KeyPoints objects expects to hold N skeletons, with dimensions of (number_of_skeletons x number_of_keypoints x keypoint_dimensions).

SkalskiP commented 1 month ago

@LinasKo are you working on "fix" for it (doc update), or should I do it?

LinasKo commented 1 month ago

@SkalskiP, I wasn't. Feel free!

Chappie74 commented 1 month ago

Thanks for the update. @LinasKo in the meanwhile, can you please point me to an example of the data for this?

I want to use it for plotting facial landmarks (if that is even possible). I have a list of x,y pairs for the center point of each landmark.

LinasKo commented 1 month ago

It's definitely possible, though it works best if you have a model already, and can call one of our connector methods: from_inference, from_ultralytics, from_mediapipe, etc.

I can't recall building a sv.KeyPoints by hand, but it shouldn't be too hard.

import supervision as sv
import numpy as np
import cv2

# wget https://media.roboflow.com/notebooks/examples/dog.jpeg
image = cv2.imread("dog.jpeg")

points = np.array([
    # Object 1
    [[100, 100], [200, 100], [200, 200], [100, 200]],

    # Object 2
    [[150, 150], [250, 150], [250, 250], [150, 250]]
])
confidence = np.array([
    [0.9, 0.8, 0.7, 0.6],
    [0.9, 0.8, 0.7, 0.6]
])
class_id = np.array([0, 1])

key_points = sv.KeyPoints(
    xy=points,
    confidence=confidence,
    class_id=class_id
)

edge_annotator = sv.EdgeAnnotator(
    edges=[
        (0, 1),
        (1, 2),
        (2, 3),
        (3, 0)
    ]
)
image = edge_annotator.annotate(image.copy(), key_points)

sv.plot_image(image)
Chappie74 commented 1 month ago

Makes sense now. Thank you.

LinasKo commented 4 weeks ago

@SkalskiP, This is very small, so I'm taking it and deploying together with other small fixes. Addressed by: #1448