Keypoints: rm NAS skeleton, improve docs examples

This commit is contained in:
Linas Kondrackis
2024-04-25 15:00:01 +03:00
parent c8c2ff5c45
commit 399342513a
2 changed files with 8 additions and 28 deletions
+8 -4
View File
@@ -50,7 +50,8 @@ class KeyPoints:
xy: npt.NDArray[np.float32]
class_id: Optional[npt.NDArray[np.int_]] = None
confidence: Optional[npt.NDArray[np.float32]] = None
data: Dict[str, Union[npt.NDArray[Any], List]] = field(default_factory=dict)
data: Dict[str, Union[npt.NDArray[Any], List]
] = field(default_factory=dict)
def __post_init__(self):
validate_keypoints_fields(
@@ -130,7 +131,8 @@ class KeyPoints:
xy = ultralytics_results.keypoints.xy.cpu().numpy()
class_id = ultralytics_results.boxes.cls.cpu().numpy().astype(int)
class_names = np.array([ultralytics_results.names[i] for i in class_id])
class_names = np.array([ultralytics_results.names[i]
for i in class_id])
confidence = ultralytics_results.keypoints.conf.cpu().numpy()
data = {CLASS_NAME_DATA_FIELD: class_names}
@@ -151,13 +153,15 @@ class KeyPoints:
Example:
```python
import cv2
import torch
import supervision as sv
import super_gradients
image = cv2.imread(<SOURCE_IMAGE_PATH>)
device = "cuda" if torch.cuda.is_available() else "cpu"
yolo_nas = super_gradients.training.models.get(
"yolo_nas_pose_s", pretrained_weights="coco_pose").to("cuda")
"yolo_nas_pose_s", pretrained_weights="coco_pose").to(device)
results = yolo_nas.predict(image, conf=0.1)
keypoints = sv.KeyPoints.from_yolo_nas(results)
@@ -180,7 +184,7 @@ class KeyPoints:
def __getitem__(
self, index: Union[int, slice, List[int], np.ndarray, str]
) -> Union["KeyPoints", List, np.ndarray, None]:
) -> Union[KeyPoints, List, np.ndarray, None]:
"""
Get a subset of the KeyPoints object or access an item from its data field.
-24
View File
@@ -25,30 +25,6 @@ class Skeleton(Enum):
(17, 15),
]
# Hardcoding here, but it also comes within model results
# Note: the classes in the model are 0-indexed, while the skeleton is 1-indexed
YOLO_NAS = [
(0, 1),
(0, 2),
(1, 2),
(1, 3),
(2, 4),
(3, 5),
(4, 6),
(5, 6),
(5, 7),
(5, 11),
(6, 8),
(6, 12),
(7, 9),
(8, 10),
(11, 12),
(11, 13),
(12, 14),
(13, 15),
(14, 16),
]
SKELETONS_BY_EDGE_COUNT: Dict[int, Edges] = {}
SKELETONS_BY_VERTEX_COUNT: Dict[int, Edges] = {}