【问题标题】:How to access the save results of yolov5 in different folder?如何访问不同文件夹中yolov5的保存结果?
【发布时间】:2022-11-10 17:33:18
【问题描述】:

我正在使用下面的代码来加载经过训练的自定义 Yolov5 模型并执行检测。

import cv2
import torch
from PIL import Image

model = torch.hub.load('ultralytics/yolov5', 'custom', 
 path='yolov5/runs/train/exp4/weights/best.pt', force_reload=True) 

img = cv2.imread('example.jpeg')[:, :, ::-1]  # OpenCV image (BGR to RGB)

results = model(img, size=416)

#显示和保存我正在使用的结果:

results.print()  
results.save() 
results.show()

我的问题是如何将结果保存在不同的目录中,以便可以在基于 Web 的应用程序中使用它们。供您参考,我正在使用 Streamlit。例如,目前,结果(图像)保存在 runs\detect\exp* 中。我想改变它。任何人都可以请指导我。

【问题讨论】:

    标签: web-applications pytorch streamlit yolov5 detectron


    【解决方案1】:

    您可以在results.save() 的函数定义中进行更改,该函数可以在文件yolov5/models/common.py 中找到。默认情况下,定义是:

    def save(self, labels=True, save_dir='runs/detect/exp'):
            save_dir = increment_path(save_dir, exist_ok=save_dir != 'runs/detect/exp', mkdir=True)  # increment save_dir
            self.display(save=True, labels=labels, save_dir=save_dir)  # save results
    

    您可以将save_dir 参数更改为所需的保存位置,文件应保存在新目录中。

    【讨论】:

      【解决方案2】:

      这对我有用,你所要做的就是使用一些论点。

      --exist-ok --name(path_where_to_save)

      例如 :

        {dataset.location}/data.yaml --weights yolov5l.pt **--exist-ok --name 
            'path_where_to_save'**
      

      为了更好地理解,您可以参考here

      【讨论】:

        【解决方案3】:

        只需将 save_dir 参数传递到您想要的目录。

        例子

        results.save(save_dir='data/output/images') 
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-10-03
          • 1970-01-01
          • 1970-01-01
          • 2016-06-18
          相关资源
          最近更新 更多