Skip to content
This repository has been archived by the owner on Jul 24, 2023. It is now read-only.

Commit

Permalink
Update test_inference.py
Browse files Browse the repository at this point in the history
  • Loading branch information
robmarkcole committed Apr 6, 2021
1 parent 21be6fd commit e014e74
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions tests/test_inference.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
import cv2
import io
import torch
from PIL import Image

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

# Images
for f in ["zidane.jpg"]: # download 2 images, 'bus.jpg'
print(f"Downloading {f}...")
torch.hub.download_url_to_file(
"https://github.com/ultralytics/yolov5/releases/download/v1.0/" + f, f
)
# img = Image.open("zidane.jpg") # PIL image, succeeds

img1 = Image.open("zidane.jpg") # PIL image
# Reading bytes fails
with open("zidane.jpg", "rb") as file:
img_bytes = file.read()
img = Image.open(io.BytesIO(img_bytes))

results = model(img1, size=640) # includes NMS

# Results
print(img.size) # validate image
results = model(img, size=640) # includes NMS
results.print()
# print(results.tolist())

# Data
# print(results.xyxy[0]) # print img1 predictions (pixels)

0 comments on commit e014e74

Please sign in to comment.