본문 바로가기

개인 공부

6/21 화_PyTorch Hub, YOLOv5 Inference Settings, Non-Maximum Suppression(NMS)

728x90

1. LOAD FROM PYTORCH HUB
This example loads a pretrained YOLOv5s model and passes an image for inference. YOLOv5 accepts URL, Filename, PIL, OpenCV, Numpy and PyTorch inputs, and returns detections in torch, pandas, and JSON output formats.

import torch

# Model
model = torch.hub.load('ultralytics/yolov5', 'yolov5s', pretrained=True)

# Images
imgs = ['https://ultralytics.com/images/zidane.jpg']  # batch of images

# Inference
results = model(imgs)

# Results
results.print()
results.save()  # or .show()

results.xyxy[0]  # img1 predictions (tensor)
results.pandas().xyxy[0]  # img1 predictions (pandas)
#      xmin    ymin    xmax   ymax  confidence  class    name
# 0  749.50   43.50  1148.0  704.5    0.874023      0  person
# 1  433.50  433.50   517.5  714.5    0.687988     27     tie
# 2  114.75  195.75  1095.0  708.0    0.624512      0  person
# 3  986.00  304.00  1028.0  420.0    0.286865     27     tie

https://pytorch.org/hub/ultralytics_yolov5/

 

2. YOLOv5 Inference Settings

model.conf = 0.25  # NMS confidence threshold
      iou = 0.45  # NMS IoU threshold
      agnostic = False  # NMS class-agnostic
      multi_label = False  # NMS multiple labels per box
      classes = None  # (optional list) filter by class, i.e. = [0, 15, 16] for COCO persons, cats and dogs
      max_det = 1000  # maximum number of detections per image
      amp = False  # Automatic Mixed Precision (AMP) inference

results = model(im, size=320)  # custom inference size

Silence Outputs

model = torch.hub.load('ultralytics/yolov5', 'yolov5s', _verbose=False)  # load silently

https://github.com/ultralytics/yolov5/issues/36

 

3. Non-Maximum Suppression(NMS)

object detection에서 한 객체에 대해 가장 신뢰도가 높은 하나의 bounding box만 남기고 그 객체와 관련된 나머지 bounding box를 없애는 후처리 과정이 (post-precessing) 필요한데, 이때 사용하는 알고리즘이 바로 NMS (Non-maximum Suppression)

https://hongl.tistory.com/180

728x90