如何获取YOLOv8目标检测模型的坐标?

huangapple go评论255阅读模式
英文:

How to get coordinates of YOLOv8 object detection model?

问题

我有一个在自定义数据上训练的YOLOv8目标检测模型。它以图像作为输入,并标注不同的对象。我的问题是如何获取不同对象的坐标?我想要这些坐标数据以进一步裁剪图像。

如果检测到的对象是人,我想要获取其坐标,同样适用于猫和狗。

提前感谢您的帮助。

我的代码看起来像这样:

infer = YOLO('path_to_trained_model.pt')
image_path = 'image'
results = infer(image_path)

class_name = "Person"
confidence_threshold = 0.5

for r in results:
    r.boxes.xyxy  # 我也遇到了这个错误:'list' object has no attribute 'xyxy'

我知道我缺少了很多数据,因为我不知道它是如何工作的。

英文:

I have a YOLOv8 object detection model trained on custom. It takes image as input and annotates the different objects my question is How do I get coordinates of different objects? I want these coordinate data to further crop the images.

If the object detected is a person I want coordinates of that same for cat and dog.

Thanks for help in advance.

My code looks something like this

infer = YOLO(r'path_to_trained_model.pt')
image_path = r'image'
results = infer(image_path)

class_name = "Person"  
confidence_threshold = 0.5 

for r in results:
    r.boxes.xyxy ## I was also getting this error 'list' object has no attribute 'xyxy'

I know I am missing quite a bit of data here since I have no idea how it works.

答案1

得分: 0

你可以像这样引用预测框的坐标:

results = model(image_path)
boxes = results[0].boxes
for box in boxes:
    print(box.xyxy)

更多信息在这里:https://docs.ultralytics.com/modes/predict/#working-with-results

box.xyxy # 框的坐标(张量)
box.cls.item() # 类别标识
box.conf.item() # 置信度值
英文:

You can refer to the predicted box coordinates like this:

results = model(image_path)
boxes = results[0].boxes
for box in boxes:
    print(box.xyxy)

More information is here: https://docs.ultralytics.com/modes/predict/#working-with-results

box.xyxy # box coordinates (tensor)
box.cls.item() # class id
box.conf.item() # confidence value

huangapple
  • 本文由 发表于 2023年6月26日 00:53:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/76551510.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定