Commit 56add208 authored by Senatilaka T.S.'s avatar Senatilaka T.S.

Delete yolov5.py

parent 14411818
import io
import torch
from PIL import Image
weights = './weights/best.pt'
model = torch.hub.load("./yolov5", 'custom', path='./weights/best.pt', source='local')
model.conf = 0.5
def yolov5(img):
results = model(img)
detected_classes = []
names = results.names
if results.pred is not None:
pred = results.pred[0]
if pred is not None:
for c in pred[:, -1].unique():
n = (pred[:, -1] == c).sum()
detected_classes.append(f"{n} {names[int(c)]}{'s' * (n > 1)}")
rendered_imgs = results.render()
converted_img = Image.fromarray(rendered_imgs[0]).convert("RGB")
return detected_classes, converted_img
def get_image_from_bytes(binary_image, max_size=614):
input_image = Image.open(io.BytesIO(binary_image)).convert("RGB")
width, height = input_image.size
resize_factor = min(max_size / width, max_size / height)
resized_image = input_image.resize(
(
int(input_image.width * resize_factor),
int(input_image.height * resize_factor),
)
)
return resized_image
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment