MCPcopy Create free account
hub / github.com/alpha2phi/python-apps / yolov5

Function yolov5

ml-yolo/backend/model/yolov5.py:15–35  ·  view source on GitHub ↗

Process a PIL image.

(img)

Source from the content-addressed store, hash-verified

13
14
15def yolov5(img):
16 """Process a PIL image."""
17
18 # Inference
19 results = model(img)
20
21 detected_classes = []
22 names = results.names
23 if results.pred is not None:
24 pred = results.pred[0]
25 if pred is not None:
26 for c in pred[:, -1].unique():
27 n = (pred[:, -1] == c).sum()
28 detected_classes.append(f"{n} {names[int(c)]}{'s' * (n > 1)}")
29
30 logging.info(f"Detected classes: {detected_classes}")
31
32 rendered_imgs = results.render()
33 converted_img = Image.fromarray(rendered_imgs[0]).convert("RGB")
34
35 return detected_classes, converted_img

Callers 2

process_yolov5Function · 0.90
process_yolov5_wsFunction · 0.90

Calls 2

renderMethod · 0.80
infoMethod · 0.45

Tested by

no test coverage detected