资讯详情

yolov5 test.py val.py detec.py 区别在哪里呢?

yolov5 test.py val.py detec.py 有什么区别?

用户在训练数据时必须使用 train.py 来进行 数据训练和验证,但我很难理解 detect.pytest.py 两者之间的区别。两者中哪一个应该在数据集中(看不见)测试数据上运行?

首先: test.py 最近被重命名为 val.py

这 3 文件是为不同的目的设计的,并使用不同设置的数据加载器。

  • train.py 数据加载器旨在兼顾速度和准确性,
  • val.py 在验证数据集中获得最佳验证数据 mAP,
  • detect.py 在现实世界中获得最好的推理结果。

每个文件的几个重要方面包括:

train.py

trainloader: LoadImagesAndLabels():旨在加载训练数据集图像和标签。可以选择使用增强能力。

 # Trainloader   dataloader, dataset = create_dataloader(train_path, imgsz, batch_size, gs, opt,                                           hyp=hyp, augment=True, cache=opt.cache_images, rect=opt.rect, rank=rank,                                           world_size=opt.world_size, workers=opt.workers,                                           image_weights=opt.image_weights, quad=opt.quad, prefix=colorstr('train: '))  

testloader: LoadImagesAndLabels():旨在加载 val 数据集图像和标签。增强能力但被禁止。

 testloader = create_dataloader(test_path, imgsz_test, batch_size * 2, gs, opt,  # testloader                                  hyp=hyp, cache=opt.cache_images and not opt.notest, rect=True, rank=-1,                                  world_size=opt.world_size, workers=opt.workers,                                  pad=0.5, prefix=colorstr('val: '))[0
       
        ] 
       
  • image size: 640
  • rectangular inference: False
  • confidence threshold: 0.001
  • iou threshold: 0.6
  • multi-label: True
  • padding: None

val.py

dataloader: LoadImagesAndLabels():设计用于加载训练、验证、测试数据集图像和标签。增强能力但被禁用。

 dataloader = create_dataloader(data[task], imgsz, batch_size, gs, single_cls, pad=0.5, rect=True, 
                                prefix=colorstr(f'{task}: '))[0] 
  • image size: 640
  • rectangular inference: True
  • confidence threshold: 0.001
  • iou threshold: 0.6
  • multi-label: True
  • padding: 0.5 * maximum stride

detect.py

dataloaders(多个):设计用于加载多种类型的媒体(images, videos, globs, directories, streams)。

 # Set Dataloader 
 vid_path, vid_writer = None, None 
 if webcam: 
     view_img = check_imshow() 
     cudnn.benchmark = True  # set True to speed up constant image size inference 
     dataset = LoadStreams(source, img_size=imgsz, stride=stride) 
 else: 
     dataset = LoadImages(source, img_size=imgsz, stride=stride) 
  • image size: 640
  • rectangular inference: True
  • confidence threshold: 0.25
  • iou threshold: 0.45
  • multi-label: False
  • padding: None

YOLOv5 PyTorch Hub Inference

models.autoShape() 类用于图像加载、预处理、推理和 NMS。有关更多信息,请参阅 YOLOv5 PyTorch Hub 教程

 class autoShape(nn.Module): 
     # input-robust model wrapper for passing cv2/np/PIL/torch inputs. Includes preprocessing, inference and NMS 
     conf = 0.25  # NMS confidence threshold 
     iou = 0.45  # NMS IoU threshold 
     classes = None  # (optional list) filter by class 
  
     def __init__(self, model): 
         super(autoShape, self).__init__() 
         self.model = model.eval() 
  
     def autoshape(self): 
  • image size: 640
  • rectangular inference: True
  • confidence threshold: 0.25
  • iou threshold: 0.45
  • multi-label: False
  • padding: None

标签: py204带紧线螺母油压变送器

锐单商城拥有海量元器件数据手册IC替代型号,打造 电子元器件IC百科大全!

锐单商城 - 一站式电子元器件采购平台