Skip to content

Commit

Permalink
feat: ✨ descriptors custom field added for keypoint and as constant name
Browse files Browse the repository at this point in the history
Signed-off-by: Onuralp SEZER <[email protected]>
  • Loading branch information
onuralpszr committed Nov 1, 2024
1 parent 933f71d commit 540516d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions supervision/config.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
CLASS_NAME_DATA_FIELD = "class_name"
ORIENTED_BOX_COORDINATES = "xyxyxyxy"
DESCRIPTORS_FIELD = "descriptors"
21 changes: 16 additions & 5 deletions supervision/keypoint/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import numpy as np
import numpy.typing as npt

from supervision.config import CLASS_NAME_DATA_FIELD
from supervision.config import CLASS_NAME_DATA_FIELD, DESCRIPTORS_FIELD
from supervision.detection.utils import get_data_item, is_data_equal
from supervision.validators import validate_keypoints_fields

Expand Down Expand Up @@ -542,8 +542,10 @@ def from_transformers(cls, transformers_results: List) -> KeyPoints:
```
""" # noqa: E501 // docs

keypoints_list = []
scores_list = []
keypoints_list: List[np.ndarray] = []
scores_list: List[np.ndarray] = []
descriptors_list: List[np.ndarray] = []
data: Dict[str, Any] = {}

for result in transformers_results:
if "keypoints" in result:
Expand All @@ -554,12 +556,21 @@ def from_transformers(cls, transformers_results: List) -> KeyPoints:
keypoints_list.append(keypoints)
scores_list.append(scores)

if "descriptors" in result:
descriptors = result["descriptors"].detach().numpy()

if descriptors.size > 0:
descriptors_list.append(descriptors)

if not keypoints_list:
return cls.empty()

if descriptors_list:
data[DESCRIPTORS_FIELD] = np.array(descriptors_list)

return cls(
xy=np.array(keypoints_list,dtype=np.float32),
confidence=np.array(scores_list,dtype=np.float32),
xy=np.array(keypoints_list, dtype=np.float32),
confidence=np.array(scores_list, dtype=np.float32),
)

def __getitem__(
Expand Down

0 comments on commit 540516d

Please sign in to comment.