首页 > 其他分享 >YOLOv7

YOLOv7

时间:2022-11-10 12:00:11浏览次数:58  
标签:YOLOv7 image torch nimg import output model

YOLOv7

CSDN文章

使用Git Bash 输入命令

成功运行keypoint.py

#!/usr/bin/env python
# coding: utf-8

# In[ ]:


import matplotlib.pyplot as plt
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, plot_skeleton_kpts


# In[ ]:


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.half().to(device)


# In[ ]:


image = cv2.imread('./xingren1.webp') # 需要检测的文件相对地址
image = letterbox(image, 960, stride=64, auto=True)[0]
image_ = image.copy()
image = transforms.ToTensor()(image)
image = torch.tensor(np.array([image.numpy()]))

if torch.cuda.is_available():
    image = image.half().to(device)   
output, _ = model(image)


# In[ ]:


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)
nimg = image[0].permute(1, 2, 0) * 255
nimg = nimg.cpu().numpy().astype(np.uint8)
nimg = cv2.cvtColor(nimg, cv2.COLOR_RGB2BGR)
for idx in range(output.shape[0]):
    plot_skeleton_kpts(nimg, output[idx, 7:].T, 3)


cv2.imwrite('keypointFirst.jpg', nimg) # 写入结果的文件名

# In[5]:


# get_ipython().run_line_magic('matplotlib', 'inline')
# plt.figure(figsize=(8,8))
# plt.axis('off')
# plt.imshow(nimg)
# plt.show()


# In[ ]:

10/11/2022 记


标签:YOLOv7,image,torch,nimg,import,output,model
From: https://www.cnblogs.com/POLAYOR/p/16876611.html

相关文章

  • YOLOv7--detect.py 解析之 torch.jit.trace 的应用
    1.什么是JIT?JIT是一种概念,全称是JustInTimeCompilation,中文译为「即时编译」,是一种程序优化的方法。在深度学习中JIT的思想更是随处可见,最明显的例子就是Keras......
  • YOLOv7 训练命令
    多GPU后台分布式训练:#后台从头训练不要忘记&后面加上&符号,可以使得我们就算关掉了session连接,远程服务器也可以保持训练任务的运行。nohuppython-mtorch.distribu......