yolov8Pose combat


foreword

The YOLO series emerge in endlessly, from yolov5 to the current yolov8 in less than a year. Track new technologies, understand cutting-edge algorithms, let's test the effect of yolov8 on different characters such as pose detection!


1. yolov8 environment construction

1.1 Source code: git

1.2 Install the necessary packages:

Installation notes: yolo5 is compatible with python3.7 and the corresponding numpy; and yolo8 uses python3.8 or above.
Otherwise you will encounter problems:

  1. TypeError: concatenate() got an unexpected keyword argument ‘dtype’ #2029
  • Solution: conda a new environment, python=3.8 and directly pip install ultralytics
  1. According to the above operation, I also encountered a bug:
    F.conv2d(input, weight, bias, self.stride,
    RuntimeError: GET was unable to find an engine to execute this computation"
  • Solution reference: Issue

In addition, domestic firewalls may prohibit the download of certain packages, especially large files related to pytorch. You can refer to the domestic mirror download package

2. Test

Train the model, evaluate the model, and export the model

from ultralytics import YOLO

# Create a new YOLO model from scratch
model = YOLO('yolov8n.yaml')

# Load a pretrained YOLO model (recommended for training)
model = YOLO('yolov8n.pt')

# Train the model using the 'coco128.yaml' dataset for 3 epochs
results = model.train(data='coco128.yaml', epochs=3)

# Evaluate the model's performance on the validation set
results = model.val()

# Perform object detection on an image using the model
results = model('https://ultralytics.com/images/bus.jpg')

# Export the model to ONNX format
success = model.export(format='onnx')

You can successfully train and evaluate and export the onnx model file.
insert image description here

Measured detection effect

Take a photo to test the above trained model

from ultralytics import YOLO
from PIL import Image
import cv2

model = YOLO("model.pt")

# accepts all formats - image/dir/Path/URL/video/PIL/ndarray. 0 for webcam
results = model.predict(source="0")
results = model.predict(source="folder", show=True) # Display preds. Accepts all YOLO predict arguments

# from PIL
im1 = Image.open("bus.jpg")
results = model.predict(source=im1, save=True)  # save plotted images

# from ndarray
im2 = cv2.imread("bus.jpg")
results = model.predict(source=im2, save=True, save_txt=True)  # save predictions as labels

# from list of PIL/ndarray
results = model.predict(source=[im1, im2])

The measured results are as follows:
insert image description here

Testing Human Pose Estimation

Turn on the camera to detect the posture of the person

from ultralytics import YOLO
import cv2
import math
import os
import glob
import numpy as np

# Load a model
model = YOLO('yolov8n-pose.pt')  # load an official model
# model = YOLO('path/to/best.pt')  # load a custom trained

video_path = 0
cap = cv2.VideoCapture(video_path)

while cap.isOpened():
    success, frame = cap.read()
    results = model(frame, imgsz=256)
    annotated_frame = results[0].plot()
    print(results[0].tojson('data.json'))
    cv2.imshow("YOLOv8 pose inference", annotated_frame)
    if cv2.waitKey(1) & 0xFF == ord("q"):
        break

cap.release()
cv2.destroyAllWindows()

insert image description here
This is the rendering of the actual measurement with the local camera turned on, and the real-time performance is good


Guess you like

Origin blog.csdn.net/wqthaha/article/details/131022201