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)
728x90
'개인 공부' 카테고리의 다른 글
7/16 토_코딩 테스트 연습(Python) (0) | 2022.07.16 |
---|---|
6/22 수_리눅스 명령어 모음 (0) | 2022.06.22 |
6/20 월_IOPub message rate (0) | 2022.06.20 |
6/18 토_리눅스 명령어(압축), Git LFS, credential.helper store (0) | 2022.06.18 |
6/16 목_YOLO v5 Models & Training Arguments, 리눅스 HDD 용량 확인 (0) | 2022.06.16 |