Yolov5获得盒子,分数,类,数字
我试图在我的项目中将对象跟踪与深度排序绑定,我需要获取框、分数、类、数字。
加载预训练的 Yolov5 模型:
model = torch.hub.load('ultralytics/yolov5', 'yolov5s', pretrained=True)
model.eval()
获取预测:
result = model(img)
print(result.shape)
print(result)
torch.Size([8, 6])
tensor([[277.50000, 379.25000, 410.50000, 478.75000, 0.90625, 2.00000],
[404.00000, 205.12500, 498.50000, 296.00000, 0.88623, 2.00000],
[262.50000, 247.75000, 359.50000, 350.25000, 0.88281, 2.00000],
[210.50000, 177.75000, 295.00000, 261.75000, 0.83154, 2.00000],
[195.50000, 152.50000, 257.75000, 226.00000, 0.78223, 2.00000],
[137.00000, 146.75000, 168.00000, 162.00000, 0.55713, 2.00000],
[ 96.00000, 130.12500, 132.50000, 161.12500, 0.54199, 2.00000],
[ 43.56250, 89.56250, 87.68750, 161.50000, 0.50146, 5.00000]], device='cuda:0')
tensor([[277.50000, 379.25000, 410.50000, 478.75000, 0.90625, 2.00000],
[404.00000, 205.12500, 498.50000, 296.00000, 0.88623, 2.00000],
[262.50000, 247.75000, 359.50000, 350.25000, 0.88281, 2.00000],
[210.50000, 177.75000, 295.00000, 261.75000, 0.83154, 2.00000],
[195.50000, 152.50000, 257.75000, 226.00000, 0.78223, 2.00000],
[137.00000, 146.75000, 168.00000, 162.00000, 0.55713, 2.00000],
[ 96.00000, 130.12500, 132.50000, 161.12500, 0.54199, 2.00000],
[ 43.56250, 89.56250, 87.68750, 161.50000, 0.50146, 5.00000]], device='cuda:0')
所以现在我的问题是如何获取每个变量中的框、分数、类、数字? 我需要它来进行对象跟踪,
我在 Pytorch 文档上的示例中尝试过一次: result.xyxy[0]
但就我而言,我收到错误:
Tensor has no attribute xyxy
im trying to bind the Object Tracking with Deep Sort in my Project and i need to get the boxes, scores, classes, nums.
Loading Pretrained Yolov5 model:
model = torch.hub.load('ultralytics/yolov5', 'yolov5s', pretrained=True)
model.eval()
Getting the Prediction:
result = model(img)
print(result.shape)
print(result)
torch.Size([8, 6])
tensor([[277.50000, 379.25000, 410.50000, 478.75000, 0.90625, 2.00000],
[404.00000, 205.12500, 498.50000, 296.00000, 0.88623, 2.00000],
[262.50000, 247.75000, 359.50000, 350.25000, 0.88281, 2.00000],
[210.50000, 177.75000, 295.00000, 261.75000, 0.83154, 2.00000],
[195.50000, 152.50000, 257.75000, 226.00000, 0.78223, 2.00000],
[137.00000, 146.75000, 168.00000, 162.00000, 0.55713, 2.00000],
[ 96.00000, 130.12500, 132.50000, 161.12500, 0.54199, 2.00000],
[ 43.56250, 89.56250, 87.68750, 161.50000, 0.50146, 5.00000]], device='cuda:0')
tensor([[277.50000, 379.25000, 410.50000, 478.75000, 0.90625, 2.00000],
[404.00000, 205.12500, 498.50000, 296.00000, 0.88623, 2.00000],
[262.50000, 247.75000, 359.50000, 350.25000, 0.88281, 2.00000],
[210.50000, 177.75000, 295.00000, 261.75000, 0.83154, 2.00000],
[195.50000, 152.50000, 257.75000, 226.00000, 0.78223, 2.00000],
[137.00000, 146.75000, 168.00000, 162.00000, 0.55713, 2.00000],
[ 96.00000, 130.12500, 132.50000, 161.12500, 0.54199, 2.00000],
[ 43.56250, 89.56250, 87.68750, 161.50000, 0.50146, 5.00000]], device='cuda:0')
so now my question is how do i get the boxes, scores, classes, nums in each variables?
I need that for the Object Tracking
I tried it once with the example on Pytorch Documentation:result.xyxy[0]
but in my Case I get an Error:
Tensor has no attribute xyxy
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
模型的输出是火炬张量,没有 xyxy 方法。您需要手动提取值。您可以一一检查每个检测:
或者您可以通过以下方式对检测张量进行切片:
The output from the model is a torch tensor and has no xyxy method. You need to extract the values manually. Either you can go through each detection one by one:
or you can slice the detections tensor by: