【问题标题】:yoloV8: how I can to predict and save the image with boxes on the objects with pytorchyoloV8:我如何使用 pytorch 预测和保存对象上带有框的图像
【发布时间】:2023-02-14 01:42:43
【问题描述】:
import torch
import glob
import os
import pathlib
from ultralytics import YOLO

model_name='MyBest.pt'
model = torch.hub.load(<?>, 'custom', source='local', path = model_name, force_reload = True)
results = model(person.png)  # predict on an image
results.save()

我应该写什么:<?>

我正在尝试在所有对象上获取带有 BOX 的图像 我希望代码同时使用 yoloV8 和 pytorch

【问题讨论】:

    标签: pytorch yolo


    【解决方案1】:

    根据官方python usage source发布8.0.20:

    from ultralytics.yolo.engine.model import YOLO
    
    model = YOLO("yolov8s.pt")
    results = model.predict(source='ultralytics/assets', save=True, save_txt=True)
    

    【讨论】:

    • 谢谢。但我尝试使用模型并用对象上的框保存
    • 更新评论!这将保存带有预测和框的图像
    【解决方案2】:

    您可以使用这些代码了解更多详情:

    for result in results:
       boxes = result.boxes  # Boxes object for bbox outputs
       masks = result.masks  # Masks object for segmenation masks outputs
       probs = result.probs  # Class probabilities
       print(boxes)
       print(masks)
       print(probs)
    
    
    boxes = results[0].boxes
    box = boxes[0]  # returns one box
    box.xyxy
    boxes.xyxy  # box with xyxy format, (N, 4)
    boxes.xywh  # box with xywh format, (N, 4)
    boxes.xyxyn  # box with xyxy format but normalized, (N, 4)
    boxes.xywhn  # box with xywh format but normalized, (N, 4)
    boxes.conf  # confidence score, (N, 1)
    boxes.cls  # cls, (N, 1)
    boxes.data  # raw bboxes tensor, (N, 6) or boxes.boxes .
    

    您可以前往 docs.ultralytics 页面了解更多信息 https://docs.ultralytics.com/predict/

    【讨论】:

      猜你喜欢
      • 2023-01-28
      • 1970-01-01
      • 2023-02-03
      • 2015-12-19
      • 1970-01-01
      • 2019-01-19
      • 2020-03-14
      • 2021-09-15
      • 2021-06-06
      相关资源
      最近更新 更多