forked from Y-B-Class-Projects/Human-Fall-Detection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathposeEstimation.py
31 lines (27 loc) · 1.02 KB
/
poseEstimation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import torch
import cv2
from torchvision import transforms
import numpy as np
from utils.datasets import letterbox
from utils.general import non_max_suppression_kpt
from utils.plots import output_to_keypoint
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
weigths = torch.load('yolov7-w6-pose.pt', map_location=device)
model = weigths['model']
_ = model.float().eval()
if torch.cuda.is_available():
model = model.half().to(device)
def image_to_pose(path):
image = cv2.imread(path)
image = letterbox(image, 960, stride=64, auto=True)[0]
image = transforms.ToTensor()(image)
image = torch.tensor(np.array([image.numpy()]))
if torch.cuda.is_available():
image = image.half().to(device)
with torch.no_grad():
output, _ = model(image)
output = non_max_suppression_kpt(output, 0.25, 0.65, nc=model.yaml['nc'], nkpt=model.yaml['nkpt'],
kpt_label=True)
with torch.no_grad():
output = output_to_keypoint(output)
return output