Ultralytics YOLO를 사용한 포즈 추정
포즈 추정은 이미지에서 특정 지점(일반적으로 키포인트라고 함)의 위치를 식별하는 작업입니다. 키포인트는 관절, 랜드마크 또는 기타 두드러진 특징과 같은 객체의 여러 부분을 나타낼 수 있습니다. 키포인트 위치는 일반적으로 2D [x, y] 좌표 집합으로 표현하며, 선택적으로 가시성 플래그 [x, y, visible]을 포함할 수 있습니다.
포즈 추정 모델의 출력은 이미지 속 객체의 키포인트를 나타내는 점들의 집합이며, 일반적으로 각 점의 신뢰도 점수도 함께 포함합니다. 장면에서 객체의 특정 부분과 해당 부분 간의 상대적 위치를 식별해야 할 때 포즈 추정이 적합합니다.
시청: Ultralytics YOLO26으로 실시간 포즈 추정을 실행하는 방법 | 추적 및 키포인트 추출 🕺
YOLO26 Pose 모델은 -pose 접미사를 사용합니다(예: yolo26n-pose.pt). 이 모델은 COCO 키포인트로 사전 학습되었습니다.
모델#
COCO 키포인트 데이터셋으로 사전 학습된 YOLO26 Pose 모델은 아래와 같습니다.
모델은 처음 사용할 때 최신 Ultralytics 릴리스에서 자동으로 다운로드됩니다.
| 모델 | 크기 (픽셀) | mAP포즈50-95 (e2e) | mAP포즈50 (e2e) | 속도 CPU ONNX (ms) | 속도 T4 TensorRT10 (ms) | 파라미터 (M) | FLOPs (B) |
|---|---|---|---|---|---|---|---|
| YOLO26n-pose | 640 | 57.2 | 83.3 | 40.3 ± 0.5 | 1.8 ± 0.0 | 2.9 | 7.6 |
| YOLO26s-pose | 640 | 63.0 | 86.6 | 85.3 ± 0.9 | 2.7 ± 0.0 | 10.4 | 24.1 |
| YOLO26m-pose | 640 | 68.8 | 89.6 | 218.0 ± 1.5 | 5.0 ± 0.1 | 21.5 | 73.3 |
| YOLO26l-pose | 640 | 70.4 | 90.5 | 275.4 ± 2.4 | 6.5 ± 0.1 | 25.9 | 91.7 |
| YOLO26x-pose | 640 | 71.6 | 91.6 | 565.4 ± 3.0 | 12.2 ± 0.2 | 57.6 | 202.3 |
- mAPval 값은 COCO Keypoints val2017 데이터셋에서 단일 모델, 단일 스케일로 측정한 값입니다.
yolo pose val data=coco-pose.yaml device=0 nms=False로 재현할 수 있습니다. - 속도는 CPU의 ONNX와 NVIDIA T4 GPU의 TensorRT10을 사용하여 COCO val 이미지에서 측정한 평균값입니다.
yolo pose val data=coco-pose.yaml batch=1 device=0|cpu nms=False로 재현할 수 있습니다. - Params 및 FLOPs 값은 Conv/BatchNorm 폴딩과 사용하지 않는 감지 브랜치 제거 후의 융합 모델 기준입니다. 사전 학습된 체크포인트에는 전체 학습 아키텍처가 유지되므로 값이 더 높을 수 있습니다.
예비 COCO 키포인트 결과는 미출시 YOLO27 미리 보기를 참조하세요.
학습#
이미지 크기 640으로 COCO8-pose 데이터셋에서 100 에포크 동안 YOLO26n-pose 모델을 학습합니다.
from ultralytics import YOLO
# 모델 로드
model = YOLO("yolo26n-pose.yaml") # YAML에서 새 모델을 생성합니다.
model = YOLO("yolo26n-pose.pt") # 사전 학습된 모델을 불러옵니다(학습에 권장).
model = YOLO("yolo26n-pose.yaml").load("yolo26n-pose.pt") # YAML에서 모델을 생성하고 가중치를 전이합니다.
# 모델 학습
results = model.train(data="coco8-pose.yaml", epochs=100, imgsz=640)전체 train 모드 세부 정보는 학습 페이지를 참조하세요. Ultralytics Platform 클라우드 학습을 사용하여 포즈 모델을 학습할 수도 있습니다.
데이터셋 형식#
YOLO 포즈 데이터셋 형식에 대한 자세한 내용은 데이터셋 가이드를 참조하세요. 기존 COCO 키포인트 JSON 데이터셋을 YOLO 형식으로 변환하려면 COCO에서 YOLO로 변환하는 가이드에 설명된 대로 기본 제공 convert_coco 함수를 use_keypoints=True와 함께 사용하세요. Ultralytics Platform 주석은 사람, 손, 얼굴 및 사용자 지정 키포인트 레이아웃을 위한 기본 제공 스켈레톤 템플릿과 포즈 라벨도 지원합니다.
사용자 지정 포즈 추정 작업에는 동물 포즈 추정을 위한 Tiger-Pose, 손 추적을 위한 Hand Keypoints, 개의 포즈 분석을 위한 Dog-Pose와 같은 특수 데이터셋도 살펴볼 수 있습니다.
검증#
학습된 YOLO26n-pose 모델의 정확도를 평균 정밀도(mAP)로 측정해 검증합니다. model은 학습 data와 인수를 모델 속성으로 보존하므로 인수를 지정할 필요가 없습니다. Train 예제의 path/to/best.pt은 COCO8-pose에서 검증합니다. 공식 가중치에는 현재 컴퓨터에 존재하지 않는 학습 데이터셋 경로가 기록되어 있으므로, 경고와 함께 작업 기본값인 coco8-pose.yaml로 대체됩니다. 다른 데이터셋에서 검증하려면 data을 전달하세요.
from ultralytics import YOLO
# 모델 로드
model = YOLO("yolo26n-pose.pt") # 공식 모델을 불러옵니다
model = YOLO("path/to/best.pt") # 사용자 지정 모델 로드
# 모델을 검증합니다
metrics = model.val() # 데이터셋과 설정이 기억되므로 인수가 필요하지 않습니다
metrics.box.map # map50-95
metrics.box.map50 # map50
metrics.box.map75 # map75
metrics.box.maps # 클래스별 mAP50-95; val 세트에 없는 클래스는 전체 mAP 값을 사용합니다
metrics.box.ap_class_index # 실제로 평가된 클래스 인덱스
metrics.box.image_metrics # 이미지별 박스 정밀도, 재현율, F1, TP, FP, FN을 담은 지표 딕셔너리
metrics.pose.map # map50-95(P)
metrics.pose.map50 # map50(P)
metrics.pose.map75 # map75(P)
metrics.pose.maps # 클래스별 mAP50-95(P); val 세트에 없는 클래스는 전체 mAP(P) 값을 사용합니다
metrics.pose.ap_class_index # 실제로 평가된 클래스 인덱스
metrics.pose.image_metrics # 이미지별 포즈 정밀도, 재현율, F1, TP, FP, FN을 담은 지표 딕셔너리예측#
학습된 YOLO26n-pose 모델을 사용하여 이미지에서 예측을 수행합니다.
from ultralytics import YOLO
# 모델 로드
model = YOLO("yolo26n-pose.pt") # 공식 모델을 불러옵니다
model = YOLO("path/to/best.pt") # 사용자 지정 모델 로드
# 모델로 예측을 수행합니다
results = model("https://ultralytics.com/images/bus.jpg") # 이미지에 대해 예측을 수행합니다
# 결과에 액세스합니다
for result in results:
xy = result.keypoints.xy # x 및 y 좌표
xyn = result.keypoints.xyn # normalized
kpts = result.keypoints.data # x, y, 가시성(사용 가능한 경우)Predict 페이지에서 predict 모드의 전체 세부 정보를 확인하세요.
결과 출력#
포즈 추정은 이미지마다 Results 객체 하나를 반환합니다. 주요 예측 필드는 포즈 좌표를 나타내는 result.keypoints과 해당 키포인트가 속한 감지 인스턴스를 나타내는 result.boxes입니다.
| 속성 | 유형 | 형태 | 설명 |
|---|---|---|---|
result.keypoints | Keypoints | (N) | 키포인트입니다. |
result.keypoints.data | torch.float32 | (N,K,2/3) | x,y과 선택적 가시성/신뢰도 값입니다. |
result.keypoints.xy | torch.float32 | (N,K,2) | 픽셀 좌표의 키포인트입니다. |
result.keypoints.xyn | torch.float32 | (N,K,2) | 정규화된 키포인트입니다. |
result.boxes | Boxes | (N) | 인스턴스 박스입니다. |
모든 작업에서 작업별 Results 필드를 확인하려면 작업별 예측 결과 섹션을 참조하세요.
키포인트 인덱스 맵#
기본 YOLO26 Pose 모델은 COCO 키포인트 17개를 예측하므로, result.keypoints.xy[:, k]에서 인덱스 k은 다음을 나타냅니다.
- 코
- 왼쪽 눈
- 오른쪽 눈
- 왼쪽 귀
- 오른쪽 귀
- 왼쪽 어깨
- 오른쪽 어깨
- 왼쪽 팔꿈치
- 오른쪽 팔꿈치
- 왼쪽 손목
- 오른쪽 손목
- 왼쪽 엉덩이
- 오른쪽 엉덩이
- 왼쪽 무릎
- 오른쪽 무릎
- 왼쪽 발목
- 오른쪽 발목
내보내기#
YOLO26n-pose 모델을 ONNX, CoreML 등의 다른 형식으로 내보냅니다.
from ultralytics import YOLO
# 모델 로드
model = YOLO("yolo26n-pose.pt") # 공식 모델을 불러옵니다
model = YOLO("path/to/best.pt") # 사용자 지정 모델 로드
# 모델을 내보냅니다
model.export(format="onnx")사용 가능한 YOLO26-pose 내보내기 형식은 아래 표에 나와 있습니다. format 인수를 사용하면 원하는 형식으로 내보낼 수 있습니다(예: format='onnx' 또는 format='engine'). 내보낸 모델에서 바로 예측하거나 검증할 수 있습니다(예: yolo predict model=yolo26n-pose.onnx). 내보내기가 완료되면 모델 사용 예제가 표시됩니다.
| 형식 | format 인수 | 모델 | 메타데이터 | 인수 |
|---|---|---|---|---|
| PyTorch | - | yolo26n-pose.pt | ✅ | - |
| TorchScript | torchscript | yolo26n-pose.torchscript | ✅ | imgsz, quantize, dynamic, nms, batch, device |
| ONNX | onnx | yolo26n-pose.onnx | ✅ | imgsz, quantize, dynamic, simplify, opset, nms, batch, data, fraction, device |
| OpenVINO | openvino | yolo26n-pose_openvino_model/ | ✅ | imgsz, quantize, dynamic, nms, batch, data, fraction, device |
| TensorRT | engine | yolo26n-pose.engine | ✅ | imgsz, quantize, dynamic, simplify, opset, workspace, nms, batch, data, fraction, device |
| CoreML | coreml | yolo26n-pose.mlpackage | ✅ | imgsz, dynamic, quantize, nms, batch, device |
| Apple Core AI | coreai | yolo26n-pose.aimodel | ✅ | imgsz, batch, quantize |
| TF SavedModel | saved_model | yolo26n-pose_saved_model/ | ✅ | imgsz, quantize, opset, nms, batch, data, fraction, device |
| TF GraphDef | pb | yolo26n-pose.pb | ❌ | imgsz, opset, batch, device |
| TF Edge TPU | edgetpu | yolo26n-pose_edgetpu.tflite | ✅ | imgsz, quantize, opset, data, fraction, device |
| LiteRT | litert | yolo26n-pose.tflite | ✅ | imgsz, quantize, batch, data, fraction, device |
| PaddlePaddle | paddle | yolo26n-pose_paddle_model/ | ✅ | imgsz, batch, device |
| MNN | mnn | yolo26n-pose.mnn | ✅ | imgsz, batch, dynamic, quantize, simplify, opset, nms, device |
| NCNN | ncnn | yolo26n-pose_ncnn_model/ | ✅ | imgsz, quantize, device |
| IMX500 | imx | yolo11n_imx_model/ | ✅ | imgsz, quantize, data, fraction, nms, device |
| RKNN | rknn | yolo26n-pose_rknn_model/ | ✅ | imgsz, batch, name, quantize, simplify, opset, data, fraction, device |
| ExecuTorch | executorch | yolo26n-pose_executorch_model/ | ✅ | imgsz, quantize, batch, data, fraction, device |
| Axelera | axelera | yolo26n-pose_axelera_model/ | ✅ | imgsz, batch, quantize, data, fraction, device |
| DEEPX | deepx | yolo26n-pose_deepx_model/ | ✅ | imgsz, quantize, simplify, opset, data, optimize, device |
| Qualcomm QNN | qnn | yolo26n-pose_qnn.onnx | ✅ | imgsz, batch, name, quantize, simplify, opset, data, fraction, device |
| Hailo | hailo | yolo26n-pose_hailo_model/ | ✅ | imgsz, name, quantize, data, fraction, simplify, conf, iou, device |
| Huawei Ascend | ascend | yolo26n-pose_ascend_model/ | ✅ | imgsz, batch, name, quantize, opset, simplify, nms, device |
| AMD Xilinx | xilinx | yolo26n-pose_xilinx_model/ | ✅ | imgsz, name, quantize, data, fraction, opset, simplify, device |
| NXP | nxp | yolo26n-pose_nxp.tflite | ✅ | imgsz, quantize, data, fraction, device |
| ST Edge AI | stedgeai | yolo26n-pose_stedgeai.onnx | ✅ | imgsz, quantize, data, fraction, opset, simplify, device |
nms=None은 외부 NMS를 위해 기본적으로 원시 출력을 사용합니다(YOLO26은 Axelera에서 NMS가 필요 없는 헤드를 유지합니다). 사용 가능한 NMS가 필요 없는 헤드를 선택하려면 nms=False를 설정하세요. 지원되지 않는 형식은 해당 형식의 기본 출력 경로로 대체됩니다. 위의 nms 항목은 nms=True로 NMS를 포함할 수 있는 형식을 나타냅니다.
자세한 export 내용은 내보내기 페이지를 참조하세요.
자주 묻는 질문#
Ultralytics YOLO26을 사용한 포즈 추정은 이미지에서 키포인트라고 하는 특정 지점을 식별하는 작업입니다. 이러한 키포인트는 일반적으로 관절이나 객체의 기타 주요 특징을 나타냅니다. 출력에는 각 지점의
[x, y]좌표와 신뢰도 점수가 포함됩니다. YOLO26-pose 모델은 이 작업을 위해 특별히 설계되었으며-pose접미사를 사용합니다(예:yolo26n-pose.pt). 이 모델은 COCO 키포인트와 같은 데이터셋으로 사전 학습되었으며 다양한 포즈 추정 작업에 사용할 수 있습니다. 기본 모델은 COCO 키포인트 17개를 예측합니다.사용자 지정 데이터셋으로 YOLO26-pose 모델을 학습하려면 YAML 파일로 정의한 새 모델 또는 사전 학습된 모델을 로드해야 합니다. 그런 다음 지정한 데이터셋과 매개변수를 사용하여 학습을 시작할 수 있습니다.
예제from ultralytics import YOLO # 모델 로드 model = YOLO("yolo26n-pose.yaml") # YAML에서 새 모델을 생성합니다. model = YOLO("yolo26n-pose.pt") # 사전 학습된 모델을 불러옵니다(학습에 권장). # 모델 학습 results = model.train(data="your-dataset.yaml", epochs=100, imgsz=640)학습에 대한 자세한 내용은 학습 섹션을 참조하세요. 코드 없이 사용자 지정 포즈 추정 모델을 학습하려면 Ultralytics Platform 클라우드 학습을 사용할 수도 있습니다.
YOLO26-pose 모델의 검증은 학습 중에 유지된 동일한 데이터셋 매개변수를 사용하여 정확도를 평가하는 과정입니다. 예시는 다음과 같습니다.
예제from ultralytics import YOLO # 모델 로드 model = YOLO("yolo26n-pose.pt") # 공식 모델을 불러옵니다 model = YOLO("path/to/best.pt") # 사용자 지정 모델 로드 # 모델을 검증합니다 metrics = model.val() # 데이터셋과 설정이 기억되므로 인수가 필요하지 않습니다자세한 내용은 검증 섹션을 참조하세요.
예, YOLO26-pose 모델은 ONNX, CoreML, TensorRT 등 다양한 형식으로 내보낼 수 있습니다. Python 또는 명령줄 인터페이스(CLI)를 사용하면 됩니다.
예제from ultralytics import YOLO # 모델 로드 model = YOLO("yolo26n-pose.pt") # 공식 모델을 불러옵니다 model = YOLO("path/to/best.pt") # 사용자 지정 모델 로드 # 모델을 내보냅니다 model.export(format="onnx")자세한 내용은 내보내기 섹션을 참조하세요. 내보낸 모델은 피트니스 추적, 스포츠 분석 또는 로보틱스와 같은 실시간 애플리케이션을 위해 엣지 디바이스에 배포할 수 있습니다.
Ultralytics YOLO26은 YOLO26n-pose, YOLO26s-pose, YOLO26m-pose 등 다양한 사전 학습 포즈 모델을 제공합니다. 각 모델은 크기, 정확도(mAP), 속도가 다릅니다. 모델별 COCO 키포인트 mAP, 속도, 매개변수 및 FLOPs 전체 목록은 모델 섹션을 참조하세요.
댓글465
질문을 하거나 결과를 공유하거나 다른 사람을 도와주세요.
3300299472
import pygetwindow as gw import pyautogui from ultralytics import YOLO import cv2
Load the model
model = YOLO("model/best.onnx")
while True: # Get the handle of the application window app_window = gw.getWindowsWithTitle('Chess Game')[0] app_window.activate()
# Move the window to the top-left corner of the screen app_window.moveTo(0, 0) # Set the window size to (929, 721) app_window.resizeTo(929, 721) # Get the window position left, top, width, height = app_window.left, app_window.top, app_window.width, app_window.height # Take a screenshot in the background screenshot = pyautogui.screenshot(region=(left, top, width, height)) screenshot.save('screenshot.png') # Read the screenshot and convert it to OpenCV format img = cv2.imread('screenshot.png') # Perform inference results = model.predict(source=img, show=True)I need help, who will help me? I have successfully identified the object in the program through the ONNX model, but I don't know how to obtain coordinates. I need to obtain coordinates and then control the mouse to move to the coordinates for clicking operations. Can someone show me the reference code? Thank you
1
Glenn JocherUltralytics(수정됨)@3300299472 hello! It's great to hear that you've successfully used the ONNX model for object detection. To obtain the coordinates of the detected objects and control the mouse accordingly, you can extract the bounding box coordinates from the
resultsobject and use them to move the mouse. Here's a quick example on how you can do this:from ultralytics import YOLO import pyautogui # Load the model model = YOLO("model/best.onnx") # Perform inference results = model.predict(source=img, show=True) # Get bounding box coordinates for x1, y1, x2, y2 in results[0].boxes.xyxy.tolist(): # detections in the first image # Calculate the center of the bounding box x_center = int((x1 + x2) / 2) y_center = int((y1 + y2) / 2) # Move mouse to the center of the bounding box pyautogui.moveTo(x_center, y_center) # Optionally, perform a click pyautogui.click()This code snippet will move the mouse to the center of each detected object and perform a click. Make sure to adjust the coordinates based on your specific screen resolution and application window size if necessary. Happy coding! 😊
AdadAlShabab
Hi. I want to measure the length of detected line after running the pose detection model. How can I do it? Please let me know.
1
Glenn JocherUltralyticsHi! To measure the length of a detected line after running the pose detection model, you can compute the Euclidean distance between keypoints. If you have keypoints' coordinates, you can use the following Python code example:
import numpy as np def calculate_distance(pt1, pt2): return np.sqrt((pt2[0] - pt1[0])**2 + (pt2[1] - pt1[1])**2) # Example keypoints coordinates keypoint1 = [x1, y1] # Replace x1, y1 with your actual coordinates keypoint2 = [x2, y2] # Replace x2, y2 with your actual coordinates # Calculate distance length = calculate_distance(keypoint1, keypoint2) print('The length of the line is:', length)Just replace
x1, y1, x2, y2with the actual coordinates of your keypoints. This will give you the length between these two points which can represent a line in your use case. Hope this helps! 😊
Pakorn-02(수정됨)
Can i only detect the first person entering the camera? And from the source code, can I correctly convert from key point coordinates (x, y) to position coordinates (x, y, z) in Unity?
#My Source Code import requests import cv2 import numpy as np from ultralytics import YOLO model = YOLO('yolov8n-pose.pt') cap = cv2.VideoCapture(0) server_url = 'http://localhost:3000/keypoints' while True: success, frame = cap.read() results = model(frame) # Simulate depth data (replace this with actual depth estimation) depth_data = np.random.rand(frame.shape[0], frame.shape[1]) # Access the xy attribute and convert it to a list keypoints = results[0].keypoints.xy.cpu().numpy().tolist() # data = {'keypoints': keypoints} #Extract only the keypoints for the right hand right_hand_keypoints = [keypoints[0][10]] # Combine 2D keypoints with simulated depth data to obtain 3D keypoints keypoints_3d = [(x, y, depth_data[int(y), int(x)]) for x, y in right_hand_keypoints] data = {'keypoints': keypoints_3d} # Send keypoint data to the Node.js server response = requests.post(server_url, json=data) print(response.text) # Print server response annotated_image = results[0].plot() cv2.imshow('frame', annotated_image) cv2.waitKey(1) cap.release() cv2.destroyAllWindows()1
Paula DerrengerUltralyticsHi there! Regarding your question about detecting only the first person entering the camera, YOLOv8 models by default will detect all instances of persons in each frame. However, you can modify the behavior to track the first detected person by managing the IDs of detected persons and only processing the first ID observed across frames.
As for converting from 2D keypoint coordinates (x, y) to 3D position coordinates (x, y, z) in Unity, the conversion depends on getting a real depth measurement. Your approach of simulating depth data and combining it with the keypoints is a common technique. If you have access to a depth sensor or can derive depth from stereo cameras, that would provide more accurate 3D coordinates. Just ensure that the coordinate system alignment between the AI model output and Unity's coordinate system is correctly calibrated for accurate placements in Unity.
Here's a refined approach considering depth measurements:
# Assuming depth_data contains actual depth measurements keypoints_3d = [(x, y, depth_data[int(y), int(x)]) for x, y in right_hand_keypoints]Keep refining your method to handle actual depth, and ensure coordinate transformations align with Unity's requirements. Good luck! 🚀
Pakorn-02(수정됨)
How can i convert 2D Key point value (x, y) to Position (x, y, z) on each bone in the body (3D Model) in Unity? Thanks
1
Glenn JocherUltralyticsConverting 2D keypoints to a 3D model position in Unity requires some form of depth estimation since 2D keypoints captured from images or video only provide information on the x and y axes. To add the z-axis (depth), you'll typically need additional data or a model that can infer depth from the given information.
While Ultralytics YOLOv8 specializes in pose estimation providing 2D [x, y] keypoints, integrating these with a 3D model in Unity to achieve the desired [x, y, z] positioning might involve:
- Using stereo vision techniques if you have images from multiple angles.
- Applying a separate depth estimation model that can predict the z-coordinate based on the 2D image.
- Utilizing additional sensors data (like Lidar or structured light sensors) that provides depth information.
Once you have the depth information, you can map the 2D keypoints [x, y] from YOLOv8 to 3D [x, y, z] coordinates in Unity by aligning the keypoints with the depth information.
Here's a conceptual snippet for understanding:
# Example for converting (x, y) keypoints to (x, y, z) # This assumes you have a method to retrieve 'z' (depth) depth_data = get_depth_information() # Custom method to obtain depth keypoints_2d = [(x, y) for x, y in detected_keypoints] # from YOLOv8 keypoints_3d = [(x, y, depth_data[x, y]) for x, y in keypoints_2d]In Unity, you would then apply these 3D coordinates to position the joints or bones of your model accordingly. Note that exact implementation details would depend on how you're structuring your Unity project and the source of your depth data.
Remember, working with 3D models and real-world positioning introduces complexities, especially concerning coordinate systems alignment and scale adjustments across different frameworks and data sources. 🎮🕵️♂️
leonidasavila
How can i calculate angle position between three points? Thanks
1
Paula DerrengerUltralytics@leonidasavila hey there! 👋 To calculate the angle between three points, you can use the law of cosines. Here's a quick example in Python:
import numpy as np def calculate_angle(p1, p2, p3): # p1, p2, p3 are the points in format [x, y] # Calculate the vectors v1 = np.array(p1) - np.array(p2) v2 = np.array(p3) - np.array(p2) # Calculate the angle in radians angle_rad = np.arccos(np.dot(v1, v2) / (np.linalg.norm(v1) * np.linalg.norm(v2))) # Convert to degrees angle_deg = np.degrees(angle_rad) return angle_deg # Example points p1 = [0, 0] p2 = [1, 0] p3 = [1, 1] angle = calculate_angle(p1, p2, p3) print(f"The angle is {angle} degrees")This calculates the angle at
p2formed by the line segmentsp1p2andp2p3. Hope this helps! Let me know if you have any other questions. 😊1leonidasavila
Thanks @pderrenger, for your quickly response! I´m trying to migrate our startup app from mediapipe to yolo 😍
Do you have any tutorial or short example to define specifics landmarks to make calculates? (4 example push-up)
Best regards! Leonidas
Paula DerrengerUltralyticsHey Leonidas! 🌟
It's awesome to hear about your transition from MediaPipe to YOLO for your startup app! For specific landmark detection like push-ups, you can leverage our YOLOv8 pose models. Here's a quick example to get you started:
from ultralytics import YOLO # Load a pretrained pose model model = YOLO('yolov8n-pose.pt') # Predict keypoints on an image results = model('path/to/your/image.jpg') # Access keypoints keypoints = results[0].keypoints # Now, you can use these keypoints to calculate angles or any other metrics you needThis snippet loads a pretrained YOLOv8 pose model and predicts keypoints on your image. You can then use these keypoints for further calculations, like angles between joints during push-ups.
For more detailed guidance, check out our Pose Estimation page. If you have any more questions or need further assistance, feel free to ask. Happy coding! 😊
ozankavcu38
By the way sir after loading the model how could we dissapear the pose estimatet lines like boxes=False argument
Paula DerrengerUltralytics(수정됨)Hey there! 😊 To hide the pose estimation lines (similar to using
boxes=Falsefor bounding boxes), you can simply not plot them. When you're working with the results from the pose estimation model, you have control over what gets visualized. Here's a quick example on how to display the keypoints without drawing the connecting lines:from ultralytics import YOLO # Load your pose model model = YOLO('yolov8n-pose.pt') # Run prediction results = model('path/to/image.jpg') # Access keypoints keypoints = results[0].keypoints # Now, you can visualize keypoints without drawing lines between them # This part depends on how you're visualizing. For example, using OpenCV to plot keypoints: import cv2 image = cv2.imread('path/to/image.jpg') for person in keypoints.xy: # one (17, 2) tensor per detected person for x, y in person.tolist(): cv2.circle(image, (int(x), int(y)), radius=3, color=(0, 255, 0), thickness=-1) cv2.imshow("Keypoints without lines", image) cv2.waitKey(0) cv2.destroyAllWindows()This way, you'll see the keypoints on your image without the estimated pose lines. Hope this helps, and good luck with your app migration! If you have any more questions, feel free to ask. 🚀
1Kindstep
I am currently using Yolo11 for my thesis in software engineering. Regarding the calculation of angles using keypoints, what is the correct way to access the detected keypoints directly in the code? assuming the indexing the same as in:
0: Nose 1: Left Eye 2: Right Eye 3: Left Ear 4: Right Ear 5: Left Shoulder 6: Right Shoulder 7: Left Elbow 8: Right Elbow 9: Left Wrist 10: Right Wrist 11: Left Hip 12: Right Hip 13: Left Knee 14: Right Knee 15: Left Ankle 16: Right Ankle
So assuming i use a similar function as you proposed, to calculate the angle of the right elbow joint a live feed (e.g. webcam) and the code is something like this:
model = YOLO('yolo11x-pose.pt')
results = model(frame, show=True, conf=conf, device=device, save=True)
keypoints = results[0].keypoints
angle = calculate_angle(keypoints6, keypoints8, keypoints10) # print(f"The angle is {angle} degrees")
What is the correct way to access each keypoint? Is it indexed in a array like keypoints[6] or what would be the correct way to go forward?
I hope my question is not too messy. It's getting quite late, but I am enjopying my time working with Yolo11.
1Kindstep
Whoops, was not meant to be edited like that :D
Glenn JocherUltralyticsTo access specific keypoints in YOLO11 pose estimation, you can index the
keypointsarray directly using the indices corresponding to each body part. For example, to calculate the angle at the right elbow, you can usekeypoints[6],keypoints[8], andkeypoints[10]for the right shoulder, right elbow, and right wrist, respectively. Let me know if you need further assistance!Kindstep
Okay, i Already figured it out now that I had time to try it. Seems I was on the right track. :)
Have a great weekend everybody!
1leonidasavila
@kindstep thanks for sharing. Good luck with your thesis, it's will be fine! Currently, we are using YOLO8 and we are studying to migrate YOLO11... I hope the deploy of hand pose very soon!
Cosophia
What task does line annotation correspond to? what I know is : rectangle -> detection point -> pose polygon -> Segment
Paula DerrengerUltralyticsA line annotation does not map to a standalone Ultralytics task. Use pose estimation when the line represents connections between labeled keypoints, or segmentation when you need the line’s pixel-level shape; please continue dropping questions here so the Ultralytics team can assist.
yacinehrb
Is it possible to use byte tracking with YoloPose26 ?
Glenn JocherUltralyticsYes — Ultralytics YOLO26 pose models can be used with ByteTrack through Track mode; feel free to post any follow-up details here so the Ultralytics team can see them, and the pose docs and Track mode docs cover the supported workflow.
JC3
Ok... but where is the documentation on how to actually run the model and access the results? Seems to be missing.
Glenn JocherUltralyticsYou can run a pose model via Python or CLI; the returned
resultsobjects expose keypoints directly—see the usage pattern on the Pose Estimation docs (and feel free to drop any follow-up questions here so the Ultralytics team can see them).from ultralytics import YOLO model = YOLO("yolo26n-pose.pt") results = model("path/to/image.jpg") # or a video path / 0 for webcam r = results[0] xy = r.keypoints.xy # (n, k, 2) pixel coords xyn = r.keypoints.xyn # (n, k, 2) normalized coords kpts = r.keypoints.data # (n, k, 3) x, y, visible/conf (if available)yolo pose predict model=yolo26n-pose.pt source=path/to/image.jpg
shayan-mesdaghi
Hello everyone, I trained a YOLO model on a dataset I created myself. The training went well, but I have a major problem: why isn't the skeleton (landmarks connections) displayed on my images and videos, and only the keypoints are shown? I performed the labelling process using Roboflow. I should mention that when I use a pre-trained YOLO model, the skeleton is displayed, but when I train the dataset myself, only the keypoints are present. Please guide me, thank you.
Glenn JocherUltralytics@shayan-mesdaghi skeleton lines are auto-drawn only for the COCO 17‑keypoint human schema; custom keypoint counts/orders show dots unless you render your own connections. If you’re not using the COCO 17 order, set your skeleton at draw time like this:
from ultralytics import YOLO from ultralytics.utils.plotting import Annotator # 1-based COCO-17 pairs; adjust to your schema as needed skeleton = [(16,14),(14,12),(17,15),(15,13),(12,13),(6,12),(7,13),(6,7), (6,8),(7,9),(8,10),(9,11),(2,3),(1,2),(1,3),(2,4),(3,5),(4,6),(5,7)] model = YOLO("best.pt") for r in model("image_or_video.mp4"): im = r.orig_img.copy() ann = Annotator(im) ann.skeleton = skeleton # 1-based indices for k in r.keypoints.xy: ann.kpts(k, kpt_line=True) im_out = ann.result()If you edited
plotting.py, restart your Python session/notebook so changes load. Method details are in the Annotator.kpts reference, which notes the human‑only default forkpt_linesee Annotator.kpts, and the dataset YAML fields for pose (e.g.,kpt_shape) are shown in the Pose datasets overview.
mobin3399
Hi, I’ve trained a custom YOLOv8-pose model with two object classes. One class occupies more than 80% of the image area (large object), while the other one is much smaller. Interestingly, the smaller object produces much more accurate keypoint predictions, while the large object shows poor keypoint localization — even though both classes have precise annotations, balanced samples, and consistent lighting/camera setup.
I have already tried:
- Careful labeling (pixel-level accurate keypoints)
- Strong data augmentation
- Adjusting loss weights for keypoints and bounding boxes
- Different model scales (YOLOv8n-pose, YOLOv8m-pose)
However, the issue remains: pose accuracy drops significantly for the larger object, despite good detection and validation metrics.
From my analysis, this might be related to:
- The OKS-based keypoint loss being scale-dependent (large objects are penalized less for the same absolute error).
- The receptive field or feature resolution in the pose head being insufficient for very large objects.
- Bounding box coverage (close to image borders) affecting normalized keypoint coordinates.
Has anyone else observed this behavior in YOLOv8-pose or YOLOv9-pose? And is there a recommended way to make keypoint accuracy more scale-invariant (for example, by modifying the OKS loss or normalization strategy)?
Any guidance or similar experiences would be greatly appreciated!
pratikbariya
Ok, you have done proper annotation, augmentation, loss weight adjustments, and tried different models. See, there is an issue regarding YOLOV8-POSE for large objects. I think you have to focus on the KPT loss also. If it is low, then try to improve that by making changes in loss (by overriding or code changes).
If possible, share an image of the object and model matrix. That will help understand the issue.
1
Glenn JocherUltralytics(수정됨)@pratikbariya @mobin3399 adding a few concrete levers you can try for the “large object → poorer keypoint localization” case: train/val at higher resolution and lighter augments for pose, e.g.
imgsz=1280 mosaic=0.0 degrees=0 translate=0.05 scale=0.5 fliplr=0.5, and prefer images where the large object isn’t hard‑clipped by borders (pad or pre-crop so it fills the frame); if you’re not using the COCO 17‑kpt schema, note our evaluator defaults to uniform OKS sigmas which can bias big objects—set explicit sigmas for your keypoints or adopt the COCO set; details and usage are in the Pose docs and PoseValidator notes.yolo pose train model=yolo26x-pose.pt data=your.yaml imgsz=1280 mosaic=0.0 degrees=0 translate=0.05 scale=0.5 fliplr=0.5See the Pose Estimation guide for end‑to‑end training tips and keypoint ordering, and the PoseValidator reference for how OKS is computed. Pose Estimation – Ultralytics YOLO • PoseValidator reference (OKS/sigma behavior)
1mobin3399
Thank you for your response. I followed your suggestion, and it helped me resolve the issue to a large extent. I really appreciate your guidance and support.
