This repository has been archived by the owner on Jul 24, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
21be6fd
commit e014e74
Showing
1 changed file
with
9 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |