2.8 KiB
2.8 KiB
Setup for web service
import ultralytics
from ultralytics import YOLO
import cv2
import numpy as np
from PIL import Image, ImageFont, ImageDraw
from IPython.display import display
import onnx
import onnxruntime
import cv2
import numpy as np
model = YOLO(r"runs\detect\train\weights\best.pt")
results = model.predict(r"val\images\IMG_1024.jpg")
result = results[0]
#box = result.boxes[0]
image 1/1 e:\tomAIto_git\tomAIto\tomato_model\val\images\IMG_1024.jpg: 640x480 2 b_fully_ripeneds, 1305.3ms Speed: 14.9ms preprocess, 1305.3ms inference, 15.3ms postprocess per image at shape (1, 3, 640, 480)
def print_box(box):
class_id, cords, conf = box
print("Object type:", class_id)
print("Coordinates:", cords)
print("Probability:", conf)
print("---")
[
print_box([
result.names[box.cls[0].item()],
[round(x) for x in box.xyxy[0].tolist()],
round(box.conf[0].item(), 2)
]) for box in result.boxes
]
Object type: b_fully_ripened Coordinates: [747, 275, 2211, 1872] Probability: 0.98 --- Object type: b_fully_ripened Coordinates: [12, 931, 1052, 1949] Probability: 0.95 ---
[None, None]